###前提・実現したいこと
先日、画像データにEXIF情報を持たせる方法について質問させていただいたのですが、参考先のソースコード(Objective-C)をswift2に書き換えることができずにお手上げ状態です…
エラー箇所が3つありますが、1つだけでも良いので、もし解決方法が分かる方が居られましたらお力をお貸しいただけないでしょうか
###参考元ソースコード
NSString *imgPath = [NSString stringWithFormat:@"%@/sample.jpg", [[NSBundle mainBundle] resourcePath]]; CGImageSourceRef cgImage = CGImageSourceCreateWithURL((CFURLRef)[NSURL fileURLWithPath:imgPath], nil); NSMutableDictionary* exifDict = [[[NSMutableDictionary alloc] init] autorelease]; [exifDict setObject:@"テストabc123" forKey:(NSString*)kCGImagePropertyExifUserComment]; NSMutableData* imageData = [[[NSMutableData alloc] init] autorelease]; CGImageDestinationRef dest = CGImageDestinationCreateWithData((CFMutableDataRef)imageData, CGImageSourceGetType(cgImage), 1, nil); CGImageDestinationAddImageFromSource(dest, cgImage, 0, (CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys: exifDict, (NSString*)kCGImagePropertyExifDictionary, nil]); CGImageDestinationFinalize(dest); NSString *exportPath = [NSString stringWithFormat:@"%@/export.jpg", [[NSBundle mainBundle] resourcePath]]; NSLog(@"exportPath : %@", exportPath); [imageData writeToFile:exportPath atomically:YES]; CFRelease(cgImage); CFRelease(dest);
###swift変換後ソースコード
var imgPath: String = "\(NSBundle.mainBundle().resourcePath)/sample.jpg" var cgImage: CGImageSourceRef = CGImageSourceCreateWithURL(NSURL.fileURLWithPath(imgPath), nil)! var exifDict = NSMutableDictionary() exifDict.setObject("テストabc123", forKey: kCGImagePropertyExifUserComment) //エラー1 var imageData: NSMutableData = NSMutableData() var dest: CGImageDestinationRef = CGImageDestinationCreateWithData(imageData, CGImageSourceGetType(cgImage)!, 1, nil)! CGImageDestinationAddImageFromSource(dest, cgImage, 0, NSDictionary.dictionaryWithObjectsAndKeys(exifDictkCGImagePropertyExifDictionarynil)) //エラー2 CGImageDestinationFinalize(dest) var exportPath: String = "\(NSBundle.mainBundle().resourcePath)/export.jpg" NSLog("exportPath : %@", exportPath) imageData.writeToFile(exportPath, atomically: true) CFRelease(cgImage) //エラー3 CFRelease(dest) //エラー3
###swiftコードのエラー内容
エラー1:Argument type 'CFString' does not conform to expected type 'NSCopying'
エラー2:Use of unresolved identifier 'exifDictkCGImagePropertyExifDictionarynil'
エラー3:Core Foundation objects are automatically memory managed
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/29 18:06