그 안에 포함 된 메타 데이터와 JPEG을 얻고 싶은 것입니다. 보인다
NSData *imageData = UIImageJPEGRepresentation(self.selectedImage, 0.9);
이 (당신에게 메타 데이터를 (많이)주지하는 모든 결과는 모든
첫째, 우리는 UIImageJPEGRepresentation
알라를 사용했다 ... 내가 걱정하는 모든입니다 아이폰 OS 4.2에 입수했다 EXIF, GPS 등)을 표시합니다. 충분히 공정하고 나는 그것이 잘 알려져 있다고 생각합니다.
내 테스트에 따르면 이미지 애셋의 "기본 표현"인 JPEG에는 EXIF 및 GPS 정보 (처음부터 있다고 가정)가 포함 된 모든 메타 데이터가 포함됩니다. 애셋 URL에서 애셋으로 애셋의 기본 표현 (ALAssetRepresentation)으로 이동 한 다음 getBytes 메소드/메시지를 사용하여 JPEG 이미지의 바이트를 검색하여 해당 이미지를 가져올 수 있습니다. 해당 바이트 스트림에는 앞에서 설명한 메타 데이터가 있습니다.
여기에 내가 사용하는 코드 예가 있습니다. 이미지 용으로 간주되는 애셋 URL을 사용하고 JPEG와 함께 NSData를 반환합니다. 귀하의 사용, 코드의 오류 처리 등과 관련하여주의해야합니다.
/*
* Example invocation assuming that info is the dictionary returned by
* didFinishPickingMediaWithInfo (see original SO question where
* UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=1000000050&ext=JPG").
*/
[self getJPEGFromAssetForURL:[info objectForKey:UIImagePickerControllerReferenceURL]];
// ...
/*
* Take Asset URL and set imageJPEG property to NSData containing the
* associated JPEG, including the metadata we're after.
*/
-(void)getJPEGFromAssetForURL:(NSURL *)url {
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:url
resultBlock: ^(ALAsset *myasset) {
ALAssetRepresentation *rep = [myasset defaultRepresentation];
#if DEBUG
NSLog(@"getJPEGFromAssetForURL: default asset representation for %@: uti: %@ size: %lld url: %@ orientation: %d scale: %f metadata: %@",
url, [rep UTI], [rep size], [rep url], [rep orientation],
[rep scale], [rep metadata]);
#endif
Byte *buf = malloc([rep size]); // will be freed automatically when associated NSData is deallocated
NSError *err = nil;
NSUInteger bytes = [rep getBytes:buf fromOffset:0LL
length:[rep size] error:&err];
if (err || bytes == 0) {
// Are err and bytes == 0 redundant? Doc says 0 return means
// error occurred which presumably means NSError is returned.
NSLog(@"error from getBytes: %@", err);
self.imageJPEG = nil;
return;
}
self.imageJPEG = [NSData dataWithBytesNoCopy:buf length:[rep size]
freeWhenDone:YES]; // YES means free malloc'ed buf that backs this when deallocated
}
failureBlock: ^(NSError *err) {
NSLog(@"can't get asset %@: %@", url, err);
}];
[assetslibrary release];
}
예고없이 assetLib은 비동기이므로 미리로드하지 않으면 imageJPEG가 nil이 될 수 있습니다. – rnaud
+1. 마침내 메타 데이터가 콘솔에 인쇄 된 것을 볼 수 있습니다. 좋은 대답! – gary