UIImage에 imageWithCGImage: scale: orientation: 이라는 함수가 있지만, scale로 크기만 조절할 수 있을 뿐, 이를 NSData로 옮겨도 용량은 그대로이다.
그림의 실질적인 용량이 줄기위해선 UIGraphics... 함수로 image를 다시 그려야 한다.
다음 예제 코드를 참고한다:
(http://stackoverflow.com/questions/5012695/how-to-reduce-the-uiimage-size)
UIImage *image = [actualImage you want to resize];
UIImage *tempImage = nil;
CGSize targetSize = CGSizeMake(196,110);
UIGraphicsBeginImageContext(targetSize);
CGRect thumbnailRect = CGRectMake(0, 0, 0, 0);
thumbnailRect.origin = CGPointMake(0.0,0.0);
thumbnailRect.size.width = targetSize.width;
thumbnailRect.size.height = targetSize.height;
[image drawInRect:thumbnailRect];
tempImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage *image는 원래 그림, *tempImage는 변환할 그림, targetSize는 줄어든 그림의 크기(가로, 세로 길이)이다.
'iPhone dev. > Objective C general' 카테고리의 다른 글
“_OBJC_CLASS_$_”, referenced from: error in xcode 4.3.2(코드 옮겼을 때) (0) | 2012.07.02 |
---|---|
Cyclic한 import 해결(xcode unknown type name) (0) | 2012.04.05 |
Objective C 에서 sha512 사용하기 (0) | 2011.12.05 |