2011-02-16 3 views
0

이미지 갤러리에서 액세스 한 이미지가 있습니다. 이 이미지를 데이터베이스에 저장하고 나중에 크기를 다시 지정하고 서버에 POST하려고합니다. 어떤 것이 이미지가 압축 된 경우 EXIF ​​데이터를 잃어 버릴 지 말해 줄 수 있습니까? 원본 이미지에 EXIF ​​데이터가 있습니다. 데이터가 손실되지 않은 경우. 나는 압축 및 크기 조정 이미지를 다시 할 수있는 방법에 관한 안내하시기 바랍니다iphone exif 데이터가 포함 된 이미지의 크기 (바이트)를 줄입니다

답변

4
  • 이미지 예를 들어,이 지역에 답변

부지 크기 조정 : The simplest way to resize an UIImage? 또는 자세한 내용을 https://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more

  • 이미지에 압축

다음과 같이 선언 된 UIImageJPEGRepresentation C 함수를 사용할 수 있습니다.

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

... UIImage 객체를 전달하고 압축 품질을 0.0 (최대 압축)에서 1.0 (최고 품질)까지 설정할 수 있습니다.

  • EXIF ​​손실이 EXIF을 잃지 않고 이미지를 압축 할 경우

먼저 이미지의 속성을 가져올해야 https://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more

+0

에게 답변 감사 압축. Wil 그것으로 들여다 봐 – rakendu

0

에서 답변을 참조, 데이터 UIImageJPEGRepresentation 당신은 EXIF를 포함하지 얻을.

1 getoritatinal 화상 데이터 2 providerData 3 압축 : 프랑수아 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

관련 문제