Capturing images in iOS
If reproduced, please indicate from the blog park
You need to specify an object to capture the picture. The code is not much, I'm not very good at it.
1 /**2 * Large graph cut Small map3 *4 * @param bigimg Large Map5 *6 * @return Small picture7 */8-(UIImage *) Getimagefromimage:(uiimage*) bigimg{9 Ten //Big picture Bigimage One //defines the region relative position of the Myimagerect ACGRect Myimagerect = CGRectMake (10.0,10.0,57.0,57.0);//This cgrectmake decides the position . - -uiimage* bigimage=bigimg; theCgimageref Imageref =Bigimage.cgimage; -Cgimageref Subimageref =Cgimagecreatewithimageinrect (Imageref, myimagerect); - - cgsize size; +Size.width =57.0;//These two quantities need to be set to the size of the new picture -Size.Height =57.0;// + //Methods of interception A uigraphicsbeginimagecontext (size); atCgcontextref context =Uigraphicsgetcurrentcontext (); - cgcontextdrawimage (context, myimagerect, subimageref); -uiimage* Smallimage =[UIImage imagewithcgimage:subimageref]; - Uigraphicsendimagecontext (); - - returnSmallimage; in}
There are many iosdev that may also require the following two paragraphs of code the first paragraph is the screenshot:
1 #pragmaMark-Take the screen2 /*Gets the current*/3-(UIImage *) Imagefromview: (UIView *) TheView atframe: (cgrect) Rect4 {5Uigraphicsbeginimagecontextwithoptions (Theview.frame.size,yes,1.0);6Cgcontextref context =Uigraphicsgetcurrentcontext ();7 cgcontextsavegstate (context);8 Uirectclip (rect);9 [Theview.layer Renderincontext:context];TenUIImage *theimage =Uigraphicsgetimagefromcurrentimagecontext (); One Uigraphicsendimagecontext (); A returntheimage; -}
About Uigraphicsbeginimagecontextwithoptions (theview.frame.size,yes,1.0); Need special instructions
The first parameter is the size of the captured page;
The second is whether it is opaque (see carefully oh, opaque) write yes;
The third is the quality of the picture: General write maximum (picture effect is best), that is, 1.0
The second paragraph is the code that changes the square angle to a circle (typically used to display the avatar)
1 /**2 * Picture changed to rounded corner3 *4 * @param image artwork5 * @param the size of the inset fillet6 *7 * @return cut a good figure8 */9-(uiimage*) Circleimage: (uiimage*) Image withparam: (cgfloat) inset {Ten Uigraphicsbeginimagecontext (image.size); OneCgcontextref context =Uigraphicsgetcurrentcontext (); ACgcontextsetlinewidth (Context,2); - Cgcontextsetstrokecolorwithcolor (context, [Uicolor Redcolor]. Cgcolor); -CGRect rect = CGRectMake (inset, inset, Image.size.width-inset *2.0f, Image.size.height-inset *2.0f); the cgcontextaddellipseinrect (context, rect); - Cgcontextclip (context); - - [Image Drawinrect:rect]; + cgcontextaddellipseinrect (context, rect); - Cgcontextstrokepath (context); +UIImage *newimg =Uigraphicsgetimagefromcurrentimagecontext (); A Uigraphicsendimagecontext (); at returnnewimg; -}
If there's anything wrong, I want you to point out that Exchange study
Screenshot of IOS image capture screen