简体   繁体   中英

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

    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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM