【发布时间】:2016-05-30 04:14:33
【问题描述】:
我正在使用以下裁剪方法来裁剪位于 UIImageView 中的 uiimage,然后该 UIImageView 位于 UIScrollView 中。
-(UIImage *)cropImage:(UIImage *)image
{
float scale = 1.0f/_scrollView.zoomScale;
NSLog(@"Oh and heres that zoomScale: %f", _scrollView.zoomScale);
CGRect visibleRect;
visibleRect.origin.x = _scrollView.contentOffset.x * scale;
visibleRect.origin.y = _scrollView.contentOffset.y * scale;
visibleRect.size.width = _scrollView.bounds.size.width * scale;
visibleRect.size.height = _scrollView.bounds.size.height * scale;
NSLog(@"Oh and here's that CGRect: %f", visibleRect.origin.x);
NSLog(@"Oh and here's that CGRect: %f", visibleRect.origin.y);
NSLog(@"Oh and here's that CGRect: %f", visibleRect.size.width);
NSLog(@"Oh and here's that CGRect: %f", visibleRect.size.height);
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], visibleRect);
UIImage *croppedImage = [[UIImage alloc] initWithCGImage:imageRef];
CGImageRelease(imageRef);
return croppedImage;
}
我需要将图像裁剪为 (321,115) 的 CGSize。在裁剪图像并查看打印结果后,我可以看到 visibleRect 是 (0,0,321,115) - 它应该是什么,croppedImage UIImage 然后具有宽度:321 和高度:115。但是由于某种原因,图像似乎完全放大得太远了(该方法将原始图像的一小部分裁剪为 321x115 的大小)。
为什么这种方法不能正确裁剪我的图像?
-附带说明:当我调用此方法时,我会像这样调用_croppedImage = [self cropImage:_imageView.image];,它将自定义 UIView 类的 UIImage 属性设置为裁剪后的图像。
【问题讨论】:
标签: ios uiscrollview uiimage