"IOS" iphone screenshot and add watermark

Source: Internet
Author: User

+ (UIImage *) Screenforview: (UIView *) view{//Uigraphicsbeginimagecontext (view.frame.size);//Cgcontextref context = Uigraphicsgetcurrentcontext ();//[View.layer Renderincontext:context];//UIImage *theimage = Uigraphicsgetimagefromcurrentimagecontext ();//Uigraphicsendimagecontext ();////return theimage;size_t width =view.frame.size.width;size_t Height=view.frame.size.height;size_t bitspercomponent=8;//I don't quite understand that, I mean, it means the number of digits in a color job.size_t Bytesperrow= width *4;//the number of bytes per row, ARGB each digit is 8, which is a byte, each image is 4 bytesCgcolorspaceref SpaceRef= Cgcolorspacecreatedevicergb ();//This namespace is related to grayscalevoid* data = malloc (Bytesperrow * height);//the document has a descriptionCgcontextref Context= Cgbitmapcontextcreate (data, width, height, bitspercomponent, Bytesperrow, SpaceRef, Kcgimagealphapremultipliedlast |kcgbitmapbyteorder32big);if(Context = =NULL) {NSLog (@"failed to create drawing environment");}//Rotating Screen//Flip the canvas first-affine array is very tangled, then I will write an article about affine arrayCGCONTEXTTRANSLATECTM (context, width,0); CGCONTEXTSCALECTM (Context,-1,1); CGCONTEXTTRANSLATECTM (context, width, height); CGCONTEXTROTATECTM (context, radians (-180.0));//to the current card, coordinates are rotated and the coordinates of iOS are one to thecgcontextsavegstate (context);//Save the current statecgcontextclearrect (Context, CGRectMake (0,0, width, height));//Cgcontextsetfillcolorwithcolor (context, [[Uicolor Blackcolor] cgcolor]);//cgcontextfillrect (context, CGRectMake (0, 0, width, height));//cgcontextcliptorect (context, CGRectMake (0, 0, width, height));[[View layer] renderincontext:context];//delivery to this context//Add Watermark//change coordinates, frame is useless hereCGCONTEXTTRANSLATECTM (Context, -, height- --Ten); UILabel* label = [[UILabel alloc]initwithframe:cgrectmake (0, height- -, -, -)];label.text=@"Wish"; [Label Setshadowcolor:[uicolor Graycolor]; [Label Settextcolor:[uicolor Whitecolor]; [Label Setbackgroundcolor:[uicolor Clearcolor]; [Label Setfont:[uifont boldsystemfontofsize: -]]; [Label Settextalignment:nstextalignmentcenter]; [[Label layer] renderincontext:context]; [Label release];//Adding a watermark 2CGCONTEXTTRANSLATECTM (Context,0, +); UILabel* Label2 = [[UILabel alloc]initwithframe:cgrectmake (0, height- -, -,Ten)];label2.text=@"http:/onlywish.me"; [Label2 Setshadowcolor:[uicolor Graycolor]; [Label2 Settextcolor:[uicolor Whitecolor]; [Label2 Setbackgroundcolor:[uicolor Clearcolor]; [Label2 setfont:[uifont boldsystemfontofsize: A]]; [Label2 Settextalignment:nstextalignmentcenter]; [[Label2 layer] renderincontext:context]; [Label2 release]; Cgimageref Imageref=cgbitmapcontextcreateimage (context); UIImage* result =[UIImage imagewithcgimage:imageref];//Freeing Memorycgcolorspacerelease (SPACEREF); Cgimagerelease (IMAGEREF); Cgcontextrelease (context); free (data);returnresult;}

"IOS" iphone and add watermark

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.