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();
myUIView
has dimensions 320x480 an it has some sub-views.
What is the correct way to do this?
The following snippet is used to take screenshot :
Use
renderInContext:
method instead ofdrawInContext:
methodrenderInContext:
method renders the receiver and its sublayers into current context. This method renders directly from the layer tree.I created this extension for save a screen shot from UIView
call:
If you want to create a png must change:
by
There is new API from iOS 10