ne de dahil meta verilerle JPEG almak istiyorum olmasıdır. görünüyor
NSData *imageData = UIImageJPEGRepresentation(self.selectedImage, 0.9);
(size meta verileri (çok) vermek değil: Tüm sonuçlar tüm
Öncelikle UIImageJPEGRepresentation
ala kullanıyorlardı ... umurumda olan iOS 4.2 binmiş edildi Görüntüde EXIF, GPS, vb.). Yeterince adil ve bence bu iyi biliniyor.
Testlerim, JPEG öğesinin görüntü varlığı için "varsayılan gösterimde", EXIF ve GPS bilgileri de dahil olmak üzere tüm meta verileri içerdiğini (ilk etapta olduğunu varsayarak) içerdiğini gösterir. Bu görüntüyü varlık URL'sinden Varlığa, varlığın varsayılan temsiline (ALAssetRepresentation) ve ardından JPEG görüntüsünün baytlarını almak için getBytes yöntemini/mesajını kullanarak alabilirsiniz. Bu bayt akışı içinde daha önce bahsedilen meta verilere sahiptir.
İşte bunun için kullandığım bir örnek kod. Bir resim için olduğu varsayılan bir Varlık URL'sini alır ve JPEG ile birlikte NSData'yı döndürür. imagejpeg Eğer önyüklemez yoksa nil olabilir böylece bir sonraki duyuruya vb
/*
* 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];
}
kullanımınızla ilgili kod hata işleme ile sorumluluğun alıcıya, assetLib, zaman uyumsuz olduğunu. – rnaud
+1. Sonunda konsola basılan meta verileri görmek için büyük rahatlama. Güzel cevap! – gary