3
只选择UIView的一部分
我已在为一个UIView转换成UIImage的如何转换到UIImage的
+(UIImage*) createUIImageFromView:(UIView *)view frame:(CGRect)frame;
{
if (UIGraphicsBeginImageContextWithOptions != NULL)
{
UIGraphicsBeginImageContextWithOptions(frame.size, NO, 2.0f);
}
else
{
UIGraphicsBeginImageContext(view.frame.size);
}
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
但是下面,我只能选择图像的大小,但在UIView的不是哪里应该被转换成图像。例如,如果我想转换矩形CGRect(10,10,20,20)而不是整个UIView,我该如何做?
我认为你可以在整体获得图像后进行裁剪。使用CGImage函数可以轻松完成。 – bealex