1

我有一个视图,其中我正在绘制签名我希望视图的签名部分应转换为UIImage然后在UIImageView此处显示它是我从用于转换的网络获得的代码

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

3 回答 3

2

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

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

        UIImage * myImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        return myImage;
    }
于 2013-05-14T08:38:49.963 回答
1

用我下面的方法...

- (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];
于 2013-05-14T08:37:40.433 回答
0

尝试这个:

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

第一个 endimagecontext,然后在 imageview 中设置/使用该图像

于 2013-05-14T10:48:15.740 回答