OC-图片缩放与切割

//相片缩放

- (UIImage*)imageScaledToSize:(CGSize)newSize{

UIImage* simple =self;

UIGraphicsBeginImageContext(newSize);

[simpledrawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

UIImage* newImage =UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

returnnewImage;

}


//相片剪辑

- (UIImage*)imageCutRect:(CGRect)rect{

//大图bigImage

//定义myImageRect,截图的区域

UIImage* simple =self;

CGRectmyImageRect = rect;

UIImage* bigImage= simple;

CGImageRefimageRef = bigImage.CGImage;

CGImageRefsubImageRef =CGImageCreateWithImageInRect(imageRef, myImageRect);

CGSizesize;

size.width= rect.size.width;

size.height= rect.size.height;

UIGraphicsBeginImageContext(size);

CGContextRefcontext =UIGraphicsGetCurrentContext();

CGContextDrawImage(context, myImageRect, subImageRef);

UIImage* smallImage = [UIImageimageWithCGImage:subImageRef];

UIGraphicsEndImageContext();

returnsmallImage;

}

你可能感兴趣的:(OC-图片缩放与切割)