iOS拍照获取指定区域图片

- (UIImage *)ct_imageFromImage:(UIImage *)image inRect:(CGRect)rect{

//把像 素rect 转化为 点rect(如无转化则按原图像素取部分图片)

CGFloat scale = [UIScreen mainScreen].scale;

CGFloat x= rect.origin.x*scale,y=rect.origin.y*scale,w=rect.size.width*scale,h=rect.size.height*scale;

CGRect dianRect = CGRectMake(x, y, w, h);

//截取部分图片并生成新图片

CGImageRef sourceImageRef = [image CGImage];

CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, dianRect);

UIImage *newImage = [UIImage imageWithCGImage:newImageRef scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];

return newImage;

}

你可能感兴趣的:(iOS拍照获取指定区域图片)