截取小图

来源:互联网 发布:mac 安装应用 编辑:程序博客网 时间:2024/05/16 08:33
- (UIImage*)getImageFromView:(UIView*)view atFrame:(CGRect)frame
{
   
UIGraphicsBeginImageContext(view.frame.size);
   
CGContextRef ctx = UIGraphicsGetCurrentContext();
   
CGContextSaveGState(ctx);
//    UIRectClip(frame);
    [view.
layerrenderInContext:ctx];
   
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
   
UIImage * smallImage = [UIImageimageWithCGImage:CGImageCreateWithImageInRect([imageCGImage], frame)];

   
UIGraphicsEndImageContext();
   
return smallImage;
   
}
上边代码可以实现在视图中截取指定frame的图片。
保存到相册中:UIImageWriteToSavedPhotosAlbum(smallImage,self,nil,nil);
0 0
原创粉丝点击