iOS compositing pictures

Source: Internet
Author: User

The way iOS is synthesized, I know two other kinds:

1: Direct synthesis using uiimage

Method: The picture is drawn to the context by the context to which it will be synthesized, and then the resultant picture

-(uiimage*) Ntesatcoverlaywith: (uiimage*) overlayimage{

Uigraphicsbeginimagecontext (self.size);

[Self Drawatpoint:cgpointzero];

[OverlayImage drawinrect:cgrectmake (0, 0, self.size.width, self.size.height) Blendmode:kcgblendmodenormal alpha:0. 9999999];

UIImage *combinedimage = Uigraphicsgetimagefromcurrentimagecontext ();

Uigraphicsendimagecontext ();

return combinedimage;

}

2: Through the UIView

Method: Load the picture onto a uiview and then generate the picture through UIView.

-(UIImage *) Imagefromview: (UIView *) View {

We need to size the graphics context according to the device scale

CGFloat scale = [[UIScreen mainscreen] scale];

Cgsize pageSize = view.frame.size;

Cgcolorspaceref colorspace = Cgcolorspacecreatedevicergb ();

Cgcontextref context = Cgbitmapcontextcreate (NULL,

Pagesize.width*scale,

Pagesize.height*scale,

8,/* bits per component*/

Pagesize.width*scale * 4,/* bytes per row */

ColorSpace,

Kcgimagealphapremultipliedfirst | Kcgbitmapbyteorderdefault);

Cgcolorspacerelease (ColorSpace);

Cgcontextcliptorect (context, CGRectMake (0, 0, Pagesize.width*scale, Pagesize.height*scale));

CGCONTEXTSCALECTM (context, scale, scale);

[View.layer Renderincontext:context];

Cgimageref image = Cgbitmapcontextcreateimage (context);

Cgcontextrelease (context);

UIImage *destimaage = [UIImage imagewithcgimage:image scale:1 Orientation:uiimageorientationdown | Uiimageorientationdownmirrored];

Cgimagerelease (image);

return destimaage;

}



This article is from the "share your achievements in the future" blog, please be sure to keep this source http://89092706.blog.51cto.com/9265997/1539140

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.