【发布时间】:2013-05-25 13:17:30
【问题描述】:
我有一个图像视图,显示从相机或画廊拍摄的宽高比匹配图像。在 Imageview 的顶部,我放置了一个 UIView(可移动、可缩放)。
我想相对于 UIView 的框架裁剪图像区域。
所以我这样做了:
CGImageRef imageRef = CGImageCreateWithImageInRect([myImageView.image CGImage], cropV.frame);// cropV is the UIview over the myImageView
UIImage *img = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
问题是当我这样做时,我的矩形(UIview)在图像上的实际位置(尺寸很大)是不一样的。
例如。 对于 1024x1024 图像,图像 a 在 320x480 屏幕上的宽高比调整模式下显示不同 如果我的cropV在框架上(10,10,300,300); CGImageCreateWithImageInRect 将根据 1024x1024 的图像创建图像。
有没有办法可以根据图像大小缩放cropV 帧?这样矩形(cropV)的位置只是被裁剪的那部分。
现在我在上下文中绘制图像。但这会给宽屏/优质高清照片带来模糊的裁剪。
UIGraphicsBeginImageContext(myImageView.frame.size);
[myImageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect([viewImage CGImage], cropV.frame);
【问题讨论】: