对所有各位制图专家来说,我很想知道,这两种方法中哪一种方法能更好地改造UIImage:
第一个我到场是简单而受欢迎的,是:
-(UIImage *)resizeImage:(UIImage *)image width:(CGFloat)resizedWidth height:(CGFloat)resizedHeight
{
UIGraphicsBeginImageContext(CGSizeMake(resizedWidth ,resizedHeight));
[image drawInRect:CGRectMake(0, 0, resizedWidth, resizedHeight)];
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
The second means I found in this connection ,并且似乎与上述目标相同,但比较复杂(我不真正理解其中的内容):
-(UIImage *)resizeImage:(UIImage *)image width:(CGFloat)resizedWidth height:(CGFloat)resizedHeight
{
CGImageRef imageRef = [image CGImage];
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmap = CGBitmapContextCreate(NULL, resizedWidth, resizedHeight, 8, 4 * resizedWidth, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(bitmap, CGRectMake(0, 0, resizedWidth, resizedHeight), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage *result = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap);
CGImageRelease(ref);
return result;
}
因此,我的问题是,什么方式更好,为什么?