- (UIImage *)cutImageFromImage:(UIImage *)image inRect:(CGRect)rect{
//屏幕的缩放比 (非Retain屏为1,Retain屏为2)
CGFloat s = [UIScreen mainScreen].scale;
//根据缩放比转化rect
CGRect transRect = CGRectMake(rect.origin.x*s, rect.origin.y*s, rect.size.width*s, rect.size.height*s);
//创建像素位图
CGImageRef newImageRef = CGImageCreateWithImageInRect([image CGImage], transRect);
//得到最终图片
UIImage *newImage = [UIImage imageWithCGImage:newImageRef scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];
//手动释放,否者会内存泄露
CGImageRelease(newImageRef);
return newImage;
}