The making of image watermark in iOS

Source: Internet
Author: User

Get context, the previous context is obtained in the view's DrawRect method (context layer context associated with view)

Currently we need to draw the picture to the new picture, so we need to use the bitmap context

How to get the bitmap context, note that the bitmap context is not obtained in the same way as the layer. The bitmap context requires that we create it manually.

Opens a bitmap context, noting that the bitmap context is not associated with view, so it does not need to be drawrect.

-(void) Viewdidload {

[Super Viewdidload];

Loading pictures

UIImage *image = [UIImage imagenamed:@ "small yellow Man"];

Size: The dimensions of the bitmap context (the size of the new picture)

Opaque: Opacity YES: Opaque No: Transparent, usually we are generally transparent context

Scale: Typically no scaling context is required, with a value of 0 indicating no scaling

0. Creating a Bitmap context

Uigraphicsbeginimagecontextwithoptions (image.size, NO, 0);

1. Draw the native picture

[Image Drawatpoint:cgpointzero];

2. Add text to the native image

NSString *str = @ "Small size elder brother";

Create Dictionary Properties

Nsmutabledictionary *dict = [Nsmutabledictionary dictionary];

Dict[nsforegroundcolorattributename] = [Uicolor redcolor];

Dict[nsfontattributename] = [Uifont systemfontofsize:20];

[Str drawatpoint:cgpointmake (528) withattributes:dict];

3. Generate a picture for us, get the picture from the context

UIImage *imagewater = Uigraphicsgetimagefromcurrentimagecontext ();

4. Close the context

Uigraphicsendimagecontext ();

_imageview.image = Imagewater;

}

The making of image watermark in iOS

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.