2011-02-16 77 views
0

我有從圖像庫中訪問的圖像。我想將此圖像存儲在數據庫中,稍後重新調整大小並將其張貼到服務器。如果圖像被壓縮,是否可以告訴我是否會丟失EXIF數據?我的原始圖像有EXIF數據。如果數據沒有丟失。請指導,我怎麼可以壓縮和重新大小的圖像iphone使用exif數據縮小圖像的大小(以字節爲單位)

回答

4
  • 調整圖像大小的回答

地塊在這一領域,例如:在https://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more

您可以使用UIImageJPEGRepresentation C函數,聲明爲...

NSData * UIImageJPEGRepresentation (
    UIImage *image, 
    CGFloat compressionQuality 
); 

...您可以傳遞UIImage對象,並將範圍0.0(最大壓縮)的壓縮質量設置爲1.0(最佳質量)。

  • EXIF損失

https://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more

+0

感謝您的回答。 Wil看着它 – rakendu 2011-02-17 08:53:24

0

見的答案,如果你想不失EXIF壓縮的圖像,首先你應該得到的圖像的特性,以及數據UIImageJPEGRepresentation你得到不包含EXIF。

1:getoritatinal圖像數據 2:壓縮providerData 3:WITE EXIF壓縮數據

- (void)setImagePropertyWith:(ALAsset *)asset 

{ 
     //get full imageData 
     ALAssetRepresentation * defaultRep = [asset defaultRepresentation]; 
     Byte *buffer = (Byte*)malloc(defaultRep.size); 
     NSUInteger buffered = [defaultRep getBytes:buffer fromOffset:0.0 length:defaultRep.size error:nil]; 
     NSData * data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES]; 

     // compressData providerData 
     CGDataProviderRef jpegdata = CGDataProviderCreateWithCFData((CFDataRef)data); 
     CGImageRef imageRef = CGImageCreateWithJPEGDataProvider(jpegdata, NULL, YES, kCGRenderingIntentDefault); 
     UIImage * image = [UIImage imageWithCGImage:imageRef]; 
     NSData* finaldata = UIImageJPEGRepresentation(image, 0.5); 

     //compressData with exif 
     finaldata = [self writeExif:(NSDictionary *)[self getPropertyOfdata:data] intoImage:finaldata]; 

    } 
    - (CFDictionaryRef)getPropertyOfdata:(NSData *)data 
    { 
     CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)data, NULL); 
     if (imageSource == NULL) { 
      // Error loading image 
      return nil; 
     } 
     NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: 
           [NSNumber numberWithBool:NO], (NSString *)kCGImageSourceShouldCache, 
           nil]; 
     CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (CFDictionaryRef)options); 
     NSLog(@"ori:%@",imageProperties); 
     return imageProperties; 
    // [self writeExif: (NSDictionary *)imageSource intoImageData:data]; 
    } 
+0

你忘了發佈writeExif方法 – CGR 2017-11-22 22:18:36

相關問題