如何将UIView的一部分转换为UIImage并将其显示在imageView中

如何将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]; 
+0

如何调用该方法如何将图像分配到的ImageView – 2013-05-14 08:43:06

+0

可以调用这个方法像这样'UIImage * tempImageSave = [self captureView];'并将其分配给'UIImageView',当你想捕捉图像时你可以调用这个方法 – 2013-05-14 08:48:55

+0

这个图像是暂时的还是永久的 – 2013-05-14 08:54:41

试试这个希望会对你有帮助。

- (UIImage *) getUIImageWithmyView:(UImyView *)myView 
    { 
     UIGraphicsBeginImageContextWithOptions(myView.bounds.size, myView.opaque, 0.0); 
     [myView.layer renderInContext:UIGraphicsGetCurrentContext()]; 

     UIImage * myImage = UIGraphicsGetImageFromCurrentImageContext(); 

     UIGraphicsEndImageContext(); 

     return myImage; 
    } 
+0

如何调用这种方法,我将如何抠图像到我的imageView可以请你帮我出 – 2013-05-14 08:45:38

+0

调用函数作为调用其他类像'UIImage * imageWithSig = [self getUIImageWithmyView:yourViewObject ];' – Buntylm 2013-05-14 08:49:01

+0

@JdeveloperIphone问题解决了吗? – Buntylm 2013-05-14 09:53:54

试试这个:

UIGraphicsBeginImageContext(signatureView.bounds.size); 
    [signatureView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    logoImageView.image=img; 

第一endimagecontext和集之后/使用图像中的ImageView