[英]how to convert the part of UIView into UIImage and display it in imageView
I have a view in which i am drawing the signature i want that the signature part of the view should be converted as UIImage
and then display it in UIImageView
here is the code which i got from net i am using for converting 我有一个视图,我正在绘制签名,我希望视图的签名部分应转换为
UIImage
,然后在UIImageView
显示它是我从网上获得的代码,我用于转换
UIGraphicsBeginImageContext(signatureView.bounds.size);
[signatureView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
logoImageView.image=img;
UIGraphicsEndImageContext();
Try this hope will help you. 试试这个希望对你有帮助。
- (UIImage *) getUIImageWithmyView:(UImyView *)myView
{
UIGraphicsBeginImageContextWithOptions(myView.bounds.size, myView.opaque, 0.0);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * myImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return myImage;
}
use my bellow method... 用我的波纹管方法......
- (UIImage *)captureView {
//hide controls if needed
CGRect rect = [signetureView bounds];//use your signature view's Rect means Frame;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
you can call this above method like bellow... 你可以像上面这样称呼上面这个方法......
UIImage *tempImageSave=[self captureView];
try this: 尝试这个:
UIGraphicsBeginImageContext(signatureView.bounds.size);
[signatureView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
logoImageView.image=img;
first endimagecontext and after that set/use that image in imageview 第一个endimagecontext,然后在imageview中设置/使用该图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.