Search code examples
iosiphoneobjective-cscreenshot

am using ScratchPadView for iphone app when am taking screenshot on scratchpad i have written some thing but its not showing the content


 UIGraphicsBeginImageContext(self.bounds.size );
 [self.layer renderInContext:UIGraphicsGetCurrentContext()];
 UIImage *currentScreen = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();

here am unable get the screenshot of updated scratchpad something done on scratchpad but it not showing in my screenshot ![Scratchpad screenshot][1]


Solution

  • Try something like this , if you consider to take a screenshot of UIView or UIImageView .

     UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, 1.0);// Add your view / ScratchPadView whichever you want to take Snap
        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        [[UIColor redColor] set];
        NSData *imgData =  UIImageJPEGRepresentation(image, 1.0);
        UIGraphicsEndImageContext();