我正在使用这个github图像裁剪器:https://github.com/iosdeveloper/ImageCropper
在这个图像裁剪器中,在init方法中,它们有以下几行:
CGRect rect;
rect.size.width = image.size.width;
rect.size.height = image.size.height;
[imageView setFrame:rect];
在此之前,我将图像调整到屏幕分辨率 not points。因此,如果我将代码保留在它的上面,我的UIImage将不会填充UIImageView,因为一些奇怪的原因,我也尝试过调整contentModes。
但是,如果我将其调整为这个(图像裁剪器所在的UIPopover的大小):
[imageView setFrame:CGRectMake(0, 0, 320, 480)];
UIImage 将填充UIPopover。
真正的问题是:如果我放大图像的某个部分并执行下面的代码,它将获取UIImage左上角部分的屏幕截图--不靠近我将图像裁剪到的位置。尽管它确实遵守了滚动视图的zoomScale。
下面是截图代码:
- (void)finishCropping {
float zoomScale = 1.0 / [scrollView zoomScale];
CGRect rect;
rect.origin.x = [scrollView contentOffset].x * zoomScale;
rect.origin.y = [scrollView contentOffset].y * zoomScale;
rect.size.width = [scrollView bounds].size.width * zoomScale;
rect.size.height = [scrollView bounds].size.height * zoomScale;
CGImageRef cr = CGImageCreateWithImageInRect([[imageView image] CGImage], rect);
UIImage *cropped = [UIImage imageWithCGImage:cr];
CGImageRelease(cr);
[delegate imageCropper:self didFinishCroppingWithImage:cropped];
}
有人知道为什么会这样吗?
谢谢!
发布于 2012-05-30 01:24:41
我认为您首先必须使用[UIImage imageWithCGImage:cr scale:self.scale orientation:self.imageOrientation]
而不是[UIImage imageWithCGImage:cr]
来创建UIImage
,这将解决许多关于方向的问题,并再次检查宽度和高度是否在正确的方向上。
https://stackoverflow.com/questions/10473927
复制相似问题