如何将UIView的一部分转换为UIImage并将其显示在imageView中
问题描述:
我有一个视图,其中我正在绘制签名,我希望视图的签名部分应该转换为UIImage
,然后将其显示在UIImageView
这里是这是我从网上得到的代码我使用转换如何将UIView的一部分转换为UIImage并将其显示在imageView中
UIGraphicsBeginImageContext(signatureView.bounds.size);
[signatureView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
logoImageView.image=img;
UIGraphicsEndImageContext();
答
用我的方法,波纹管...
- (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;
}
你可以调用这个上面像波纹管的方法...
UIImage *tempImageSave=[self captureView];
答
试试这个希望会对你有帮助。
- (UIImage *) getUIImageWithmyView:(UImyView *)myView
{
UIGraphicsBeginImageContextWithOptions(myView.bounds.size, myView.opaque, 0.0);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * myImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return myImage;
}
答
试试这个:
UIGraphicsBeginImageContext(signatureView.bounds.size);
[signatureView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
logoImageView.image=img;
第一endimagecontext和集之后/使用图像中的ImageView
如何调用该方法如何将图像分配到的ImageView – 2013-05-14 08:43:06
可以调用这个方法像这样'UIImage * tempImageSave = [self captureView];'并将其分配给'UIImageView',当你想捕捉图像时你可以调用这个方法 – 2013-05-14 08:48:55
这个图像是暂时的还是永久的 – 2013-05-14 08:54:41