2014-02-24 1 views
1

특정 눈금으로 initWithCGImage를 사용한 다음 UIImageJPEGRepresentation을 사용하여이 이미지에서 데이터를 가져 오면 시스템이 눈금 설정을 유지하지 못하는 것 같습니다. 왜 그런가?UIImageJPEGRepresentation 내 눈금 설정을 유지하지 않음

다음은 내 코드와 로그 내가 얻을 :

ALAssetRepresentation *rep = [asset defaultRepresentation]; 
CGImageRef iref = [rep fullResolutionImage]; 
UIImageOrientation orientation = [self orientationForAsset:asset]; 

// Scale the image       
UIImage* scaledImage = [[UIImage alloc] initWithCGImage:iref scale:2. orientation:orientation]; 
NSLog (@"Scaled image size %@", NSStringFromCGSize(scaledImage.size)); 

// Get data from image 
NSData* scaledImageData = UIImageJPEGRepresentation(scaledImage, 0.8); 

// Check the image size of the data 
UIImage* buildedImage = [UIImage imageWithData:scaledImageData]; 
NSLog (@"Data image size of %@", NSStringFromCGSize (buildedImage.size)); 

로그 제공합니다 :

"조정 된 이미지의 크기 {1944, 1296}"{3888의

"데이터 이미지 크기, 2592} "

두 이미지가 정확히 같기 때문에 정말 이상합니다.

+1

IMHO jpeg는 축척에 대해 아무 것도 모릅니다. – sage444

+0

제가 scaledImageData를 업로드하면 서버에서 크기가 조정 된 원본 크기의 이미지를 얻게됩니다. – CedricSoubrie

+1

'UIImageJPEGRepresentation'에 대해 1에 가까운 값을 주면 이미지의 품질이 떨어집니다. 그래서'0.2'처럼 작게 만드십시오. –

답변

0

- [UIImage imageWithData : scale :] 메서드를 사용해야합니다.

+0

제 문제는 scaledImageData를 업로드 할 때 서버가 크기 조정이 아닌 원래 크기의 이미지를 가져옵니다. 내 코드의 buildedImage는 업로드하기 전에 내 NSData에 실제로 무엇이 있는지 확인하는 것이 었습니다. – CedricSoubrie

+1

그러면 @ sage444의 질문에 대한 의견이 귀하의 질문에 대한 대답입니다. – EmptyStack

+0

나는 그렇게 생각한다 ... 이것은 원래 스케일로 이미지를 만들어야 함을 의미한다. 그런 다음 필요한 크기로 다른 이미지를 만들고이 두 번째 이미지에서 데이터를 보냅니다. – CedricSoubrie

관련 문제