我正在尝试在UIImage上生成UIView的缩放版本。
到目前为止,我的代码创建了UIImage,然后对其进行了缩放,但实际上我需要首先对其进行缩放,然后生成UIImage以提高性能。
代码如下:
UIGraphicsBeginImageContext([aView bounds].size);
[[aView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIGraphicsBeginImageContext(aSize);
[image drawInRect:CGRectMake(0, 0, aSize.width, aSize.height)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();其思想是让第一块代码创建具有缩放大小的图像上下文,并在该上下文中呈现的aView也进行缩放。第二个代码块应该不是必需的。
发布于 2011-11-19 04:19:58
解决方案是使用UIGraphicsBeginImageContextWithOptions(size, isOpaque, scale);创建图像上下文
https://stackoverflow.com/questions/8086272
复制相似问题