0

i need to capture image by using UIGraphicsBeginImageContextWithOptions my requirement is to start capturing from -20 from origin

any help will be highly appreciated

Abdul Karim Khan
  • 159
  • 1
  • 3
  • 14

1 Answers1

0

Use following code and Import <QuartzCore/QuartzCore.h>. You can also use this code after capturing image. So you can remove unnecessary part from that.

    UIGraphicsBeginImageContext(self.view.frame.size);
    //or
    UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);//this will also give you scaling option and more better for resolution. 

    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

    CGImageRef ref = viewImage.CGImage;


    CGRect myImageArea = CGRectMake (20, 20,
                                     300, 100);// you define coordinates according your requirements.
    CGImageRef mySubimage = CGImageCreateWithImageInRect (ref, myImageArea);

    UIImage *yourfinalcapturedimage = [UIImage imageWithCGImage:mySubimage];// this will give you your required image.

Hope, this will help you..

Nitin
  • 7,455
  • 2
  • 32
  • 51