我已经完成了图像的缩放。现在我想裁剪那个缩放的图像 有可能这样做吗? 我使用下面的代码来缩放图像。
//Scroll View settings for Zoomin-ZoomOut
Scroll.contentSize= CGSizeMake(img.frame.size.width, img.frame.size.height);
Scroll.maximumZoomScale=3.0;
Scroll.minimumZoomScale=.20;
Scroll.clipsToBounds=YES;
Scroll.delegate=self;
[Scroll addSubview:img];
Scroll.imageContainer=img;
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return img;
}
这里我使用了customScroll Class。
答案 0 :(得分:4)
如果要在滚动视图中缩放图像并想要裁剪可见区域,请尝试以下操作:
-(IBAction) cropSelecteArea
{
//Calculate the required area from the scrollview
CGRect visibleRect;
float scale = 1.0f/scrollView.zoomScale;
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;
UIImage *image = [self imageByCropping:previewImage toRect:visibleRect];
//UIImage *image = imageFromView(imageView.image, &visibleRect);
[croppedImageImageView setImage:self.objPostPikUploadPhotoPage.croppedImage];
}
- (UIImage*)imageByCropping:(UIImage *)myImage toRect:(CGRect)cropToArea{
CGImageRef cropImageRef = CGImageCreateWithImageInRect(myImage.CGImage, cropToArea);
UIImage* cropped = [UIImage imageWithCGImage:cropImageRef];
CGImageRelease(cropImageRef);
return cropped;
}