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 に答える