+ (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