1. Drawing summary:
Settings before drawing:
Cgcontextsetrgbfillcolor/cgcontextsetfillcolorwithcolor // fill color
Cgcontextsetrgbstrokecolor/cgcontextsetstrokecolorwithcolor // pen color
Cgcontextsetlinewidth // line width
Settings after drawing:
Note: The image must be painted
Use cgcontextstrokepath to describe the line, that is, the shape.
Then, cgcontextfillpath is used to fill the color in the shape.
2. Drawing common images:
Cgcontextfillrect/cgcontextfillrects
Cgcontextfillellipseinrect
Cgcontextaddrect/cgcontextaddrects
Cgcontextaddellipseinrect
Cgcontextaddlines
Cgcontextmovetopoint
Cgcontextaddlinetopoint
3. Common control methods:
Cgcontextsavegstate
Cgcontextrestoregstate
4. Create a memory image context:
Cgbitmapcontextcreate <----- cgcontextrlease release
Cgcolorspacecreatewithname (kcgcolorspacegenericrgb)
Cgcolorspacerlease
Cgbitmapcontextcreateimage () <----- cgimagerlease release.
Eg:
Cgcontextrefmycreatebitmapcontext (intpixelswide, intpixelshigh)
{
Cgcontextref context = NULL;
Cgcolorspacerefcolorspace;
Void * bitmapdata;
Int bitmapbytecount;
Int bitmapbytesperrow;
Bitmapbytesperrow = (pixelswide * 4 );
Bitmapbytecount = (bitmapbytesperrow * pixelshigh );
Colorspace = cgcolorspacecreatedevicergb ();
Bitmapdata = malloc (bitmapbytecount );
If (bitmapdata = NULL)
{
Fprintf (stderr, "memorynotallocated! ");
Returnnull;
}
Context = cgbitmapcontextcreate (bitmapdata, pixelswide, pixelshigh, 8, bitmapbytesperrow, colorspace, kcgimagealphapremultipliedlast );
If (context = NULL)
{
Free (bitmapdata );
Fprintf (stderr, "contextnotcreated! ");
Returnnull;
}
Cgcolorspacerelstrap (colorspace );
Returncontext;
}
5. Graphic Transformation:
Cgcontexttranslatectm
Cgcontextrotatectm
Cgcontextscalectm
6. Common functions:
Cgrectcontainspoint ();
Cgrectcontainsrect ();
Cgrectintersectsrect ();
Cgrectintersection ();
Cgpointequaltopoint ();
Cgsizeequaltosize ();
7. Small images from the source image.
Cgimagecreatewithimageinrect
8. screen snapshot:
# Import "quartzcore/quartzcore. H"
Uigraphicsbeginimagecontext (yourview. Frame. size );
[[Yourview layer] renderincontext: uigraphicsgetcurrentcontext ()];
Uiimage * screenshot = uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
From: http://www.cppblog.com/zhangyuntaoshe/articles/123066.html
Merge two bit Graphs into one image
To graphically merge two images into a new image, you do something like this:
Uiimage * result = nil;
Unsignedchar * Data = calloc (1, size. Width * size. Height * kbytesperpixel );
If (Data! = NULL ){
// Kcgimagealphapremultipliedlast is the pre-recorded # define value
// Set Context
Cgcontextref context = cgbitmapcontextcreate (
Data, size. Width, size. Height, 8, size. Width * kbytesperpixel,
Cgcolorspacecreatedevicergb (), kcgimagealphapremultipliedlast );
If (context! = NULL ){
Uigraphicspushcontext (context );
// Image is the downloaded background image used to compare the context
Cgcontexttranslatectm (context, 0, size. Height );
Cgcontextscalectm (context, 1,-1 );
[Image drawinrect: imagerect];
[Image2 drawinrect: image2rect];
Uigraphicspopcontext ();
Cgimageref imageref = cgbitmapcontextcreateimage (context );
If (imageref! = NULL ){
Result = [uiimageimagewithcgimage: imageref];
Cgimagerelease (imageref );
}
Cgcontextrelease (context );
}
Free (data );
}
Return result;
Key Method: cgcontextref context = cgbitmapcontextcreate ();
Cgcontexttranslatectm ();
Cgcontextscalectm ();
Cgimageref imageref = cgbitmapcontextcreateimage (context );
Cgimagerelease (imageref );
From: http://wzn860701.blog.163.com/blog/static/361528062009102502716872/