6

UIImageをでCameraRollに保存できることは知っていますがUIImageWriteToSavedPhotosAlbum、このアプローチでは、元のファイルからすべてのメタデータ(EXIF、GPSデータなど)が削除されます。画像データだけでなく、元のファイルをiOSデバイスのカメラロールに保存する方法はありますか?

編集:私はもう少し具体的にすべきだったと思います。目的は、既存のJPEGファイルの複製をユーザーのカメラロールに保存することです。これを行うための最も効率的な方法は何ですか?

4

3 に答える 3

7

保存する画像の方法に応じて、 ALAssetsLibraryが提供する方法の1つを選択できます。

– writeImageDataToSavedPhotosAlbum:metadata:completionBlock:

– writeImageToSavedPhotosAlbum:metadata:completionBlock:

(画像が実際のUIImageとしてあるか、NSDataとしてあるかによって異なります)

http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html

辞書に正しいキーを設定する必要があることに注意してください。そうしないと、正しく保存されない可能性があります。

GPS情報の例を次に示します。

NSDictionary *gpsDict = [NSDictionary dictionaryWithObjectsAndKeys:
                 [NSNumber numberWithFloat:fabs(loc.coordinate.latitude)], kCGImagePropertyGPSLatitude, 
                 ((loc.coordinate.latitude >= 0) ? @"N" : @"S"), kCGImagePropertyGPSLatitudeRef, 
                 [NSNumber numberWithFloat:fabs(loc.coordinate.longitude)], kCGImagePropertyGPSLongitude, 
                 ((loc.coordinate.longitude >= 0) ? @"E" : @"W"), kCGImagePropertyGPSLongitudeRef, 
                 [formatter stringFromDate:[loc timestamp]], kCGImagePropertyGPSTimeStamp, 
                 [NSNumber numberWithFloat:fabs(loc.altitude)], kCGImagePropertyGPSAltitude, 
                 nil];

And here is a list of the keys:

http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGImageProperties_Reference/Reference/reference.html#//apple_ref/doc/uid/TP40005103

于 2012-12-04T00:25:55.140 に答える
1

UIImagePickerControllerDelegateはあなたが探しているものです。

iOS 4.0以降では、静止画像のメタデータを静止画像とともにカメラロールに保存できます。これを行うには、Assets LibraryフレームワークのwriteImageToSavedPhotosAlbum:metadata:completionBlock:メソッドを使用します。UIImagePickerControllerMediaMetadataキーの説明を参照してください。

UIImagePickerControllerDelegateプロトコルリファレンス

于 2012-12-03T23:02:59.920 に答える
1

For a Swift solution that uses the Photos API (ALAssetLibrary is deprecated in iOS 9), you can see my solution to this problem here, including sample code.

With the Photos API, the key thing to note is that the .location property of a PHAsset does NOT embed the CLLocation metadata into the file itself, so using an EXIF viewer will not turn up any results.

これを回避するには、Photos APIを使用してカメラロールに書き込む前に、メタデータの変更を画像自体のデータに直接埋​​め込む必要があります(または、9より前のiOSバージョンでは、データを使用して一時ファイルを書き込む必要があります。埋め込まれたメタデータを作成し、ファイルのURLからPHAssetを作成します)。

また、画像データをUIImageに変換すると、メタデータが削除されるように見えるため、注意が必要です。

于 2017-04-12T17:21:43.687 に答える