2012-05-21 55 views
0

我已经完成图像的缩放。现在我想剪裁缩放的图像。
是否有可能这样做?
我用下面的代码来缩放图像。如何在xcode中裁剪缩放图像?

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

如果您缩放滚动视图,并想作物可见区域的图像试试这个:

-(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; 
}