07-21-2023, 07:33 PM
I am wondering how my iPhone app can take a screen shot of a specific `UIView` as a `UIImage`.
I tried this code but all I get is a blank image.
UIGraphicsBeginImageContext(CGSizeMake(320,480));
CGContextRef context = UIGraphicsGetCurrentContext();
[myUIView.layer drawInContext:context];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
<code>myUIView</code> has dimensions 320x480 an it has some sub-views.
What is the correct way to do this?
I tried this code but all I get is a blank image.
UIGraphicsBeginImageContext(CGSizeMake(320,480));
CGContextRef context = UIGraphicsGetCurrentContext();
[myUIView.layer drawInContext:context];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
<code>myUIView</code> has dimensions 320x480 an it has some sub-views.
What is the correct way to do this?