IOS如何在uiimageview中截取仅图像的截图

时间:2015-11-16 09:46:42

标签: ios objective-c uiimageview

我想在imageview中截取唯一的图片。我尝试过以下代码,但它会截取imageview的截图。

CGRect grabRect = CGRectMake(self.vwBackup.frame.origin.x,self.vwBackup.frame.origin.y,self.vwBackup.frame.size.width,self.vwBackup.frame.size.height);

    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
        UIGraphicsBeginImageContextWithOptions(grabRect.size, NO, [UIScreen mainScreen].scale);
    } else {
        UIGraphicsBeginImageContext(grabRect.size);
    }
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(ctx, -grabRect.origin.x, -grabRect.origin.y);
    [self.view.layer renderInContext:ctx];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
   // UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
    self.ImgEditableView.image=viewImage;

这里我附上了以上代码截图的截图:

enter image description here

1 个答案:

答案 0 :(得分:0)

$attributes