IPhone drawing Summary

Source: Internet
Author: User

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/

 

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.