1. Specify the size of the image first
Uigraphicsbeginimagecontext (view.frame.size);
2. Drawing an image in the specified area
[View DrawViewHierarchyInRect:view.bounds Afterscreenupdates:no];
3. Get the image context
UIImage *image = Uigraphicsgetimagefromcurrentimagecontext ();
4. Close the image context
Uigraphicsendimagecontext ();
That's right! It takes only 4 lines of code to get an image of the specified view.
In addition, the common drawing image has another method:
[View.layer Renderincontext:uigraphicsgetcurrentcontext ()];
Let me add a method Example:
+ (UIImage *) Getimageviewwithview: (UIView *) view{ uigraphicsbeginimagecontext (view.frame.size); [View DrawViewHierarchyInRect:view.bounds Afterscreenupdates:no]; *image = uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); return image;}
iOS simple Get view image (quartz2d)