-(UIImage*)imageByCropping:(UIScrollView*)imageToCrop toRect:(CGRect)rect
{
CGSize pageSize = rect.size;
UIGraphicsBeginImageContext(pageSize);
CGContextRef resizedContext =UIGraphicsGetCurrentContext();
CGContextTranslateCTM(resizedContext,-imageToCrop.contentOffset.x,-imageToCrop.contentOffset.y -73);
[scrollView.layer renderInContext:resizedContext];
UIImage*image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
CGRect clippedRect =CGRectMake(0,0,320,307);
picture.image =[self imageByCropping:myScrollView toRect:clippedRect];
本文介绍了一种使用Objective-C从UIScrollView中裁剪指定区域图片的方法。通过调整坐标系并渲染UIScrollView的内容到当前图像上下文中,可以获取到所需矩形区域内的图片。
3310

被折叠的 条评论
为什么被折叠?



