2D image rendering with Uigraphics do not use uigraphicsbeginimagecontext (size); Otherwise the picture will blur.
All operations of the Core Graphics API are performed in one context. So you need to get the context before drawing and pass in the function that performs the rendering. If you are rendering a picture in memory, you need to pass in the context in which the picture belongs. Getting a graphical context is the first step in completing the drawing task, and you can understand the graphical context as a canvas. If you don't get the canvas, you won't be able to complete any drawing operations. Of course, there are many ways to get a graphical context, and here I present two of the most commonly used methods of obtaining it. Call the Uigraphicsbeginimagecontextwithoptions function to get a graphical context for working with the picture. With this context, you can draw on it and generate pictures. Call the Uigraphicsgetimagefromcurrentimagecontext function to get a UIImage object from the current context. Remember to call the Uigraphicsendimagecontext function to close the graphics context after all your drawing operations. On the code:
-(UIImage *) Createshareimage: (nsstring *) str name: (nsstring *) name number: (nsstring *) Number grade: (nsstring *) grade
{
UIImage *image = [UIImage imagenamed:@ "Sharegrade"];
cgsize size=cgsizemake(image. Size. Width, image. Size. Height); // canvas size
uigraphicsbeginimagecontextwithoptions(size, NO, 0.0);
[Image Drawatpoint:cgpointmake(0, 0)];
// Get a bitmap graphics context
cgcontextref context=uigraphicsgetcurrentcontext();
Cgcontextdrawpath(context, kcgpathstroke);
// draw How many users have been defeated
[StrDrawatpoint:cgpointmake (30 image.< Span class= "S1" >size. Height*0.65) withattributes :@{nsfontattributename:[ Uifont fontwithname:@ "ARIAL-BOLDMT" size:30), nsforegroundcolorattributename:[uicolor Span class= "S1" >whitecolor]}];
//Draw the content you want to draw .....
// Returns a new drawing
UIImage *newimage=uigraphicsgetimagefromcurrentimagecontext();
Uigraphicsendimagecontext();
return newimage;
}
iOS draws text on a picture, very simple