0

我已经完成了图像的缩放。现在我想裁剪那个放大的图像。
有可能这样做吗?
我使用下面的代码来缩放图像。

//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 类。

4

1 回答 1

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;
}
于 2012-05-21T05:40:25.990 回答