2011-02-16 82 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

相关问题