그런 다음 다시 이미지를 그릴에 저장해야합니다.
// Image frame size
CGSize size = imageView.bounds.size;
// Grab a new CGContext
UIGraphicsBeginImageContextWithOptions(size, false, 0.0);
// Draw the image
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
// Grab the new image
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
위의 코드는 프레임에 이미지를 그려 테두리로 뻗어 있습니다. 어떻게 그려 지는지 다른 모드를 원한다면 직접 계산하고 "이미지 그릴"코드 줄에 원하는 것을 넣어야합니다.
- (CGRect) aspectFittedRect:(CGSize)inSize max:(CGRect)maxRect {
float originalAspectRatio = inSize.width/inSize.height;
float maxAspectRatio = maxRect.size.width/maxRect.size.height;
CGRect newRect = maxRect;
if (originalAspectRatio > maxAspectRatio) { // scale by width
newRect.size.height = maxRect.size.height * inSize.height/inSize.width;
newRect.origin.y += (maxRect.size.height - newRect.size.height)/2.0;
} else {
newRect.size.width = maxRect.size.height * inSize.width/inSize.height;
newRect.origin.x += (maxRect.size.width - newRect.size.width)/2.0;
}
return CGRectIntegral(newRect);
}
그냥
inSize
과 같은 maxRect
imageView.bounds
로 전달
imageView.image.size
:
예를 들어, 애스펙트 착용감이 알고리즘을 확인.
출처 : http://iphonedevsdk.com/forum/iphone-sdk-development-advanced-discussion/15001-aspect-fit-algorithm.html
이미지를 얻으려면하거나 이미지의 경계 (CGrect를) 싶은가? – emotality