Image watermark (personal signature on Weibo image)

Source: Internet
Author: User

-(void) viewdidload

{

[Super Viewdidload];

1. Return watermark Image

UIImage *newimage = [UIImage waterimagewithbg:@ "Scene" logo:@ "logo"];

2. Show pictures

Self.iconView.image = NewImage;

}

-(void) Testwater

{

UIImage *bgimage = [UIImage imagenamed:@ "scene"];

Ober: Based on bitmap (bitmap), all things need to be drawn to a new picture up

1. Create a bitmap-based context (open a bitmap-based context)

Size: The dimensions of the new picture

Opaque:yes: Opaque, no: transparent

This line of code is followed by a common new bitmap, the new UIImage object.

Uigraphicsbeginimagecontextwithoptions (Bgimage.size, NO, 0.0);

2. Painting background

[Bgimage drawinrect:cgrectmake (0, 0, BgImage.size.width, bgImage.size.height)];

3. Draw the watermark in the lower right corner

UIImage *waterimage = [UIImage imagenamed:@ "logo"];

CGFloat scale = 0.2;

CGFloat margin = 5;

CGFloat WATERW = waterImage.size.width * scale;

CGFloat waterh = waterImage.size.height * scale;

CGFloat Waterx = Bgimage.size.width-waterw-margin;

CGFloat watery = bgimage.size.height-waterh-margin;

[Waterimage Drawinrect:cgrectmake (Waterx, watery, waterw, Waterh)];

4. Get the finished UIImage object from the context

UIImage *newimage = Uigraphicsgetimagefromcurrentimagecontext ();

5. End Context

Uigraphicsendimagecontext ();

6. Show to Uiimageview

Self.iconView.image = NewImage;

7. Compressing the image object to binary data in PNG format

NSData *data = uiimagepngrepresentation (newimage);

UIImageJPEGRepresentation (< #UIImage *image#>, < #CGFloat compressionquality#>)

8. Writing files

NSString *path = [[Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) LastObject] stringbyappendingpathcomponent:@ "New.png"];

[Data Writetofile:path Atomically:yes];

}

Add a category to image

/**

* Water Stamp

* Return a picture with a watermark

* @param BG Background image

* @param watermark image in the bottom right corner of logo

*/

+ (Instancetype) WATERIMAGEWITHBG: (NSString *) BG Logo: (NSString *) logo

{

UIImage *bgimage = [UIImage IMAGENAMED:BG];

1. Create a bitmap-based context (open a bitmap-based context)

Uigraphicsbeginimagecontextwithoptions (Bgimage.size, NO, 0.0);

2. Painting background

[Bgimage drawinrect:cgrectmake (0, 0, BgImage.size.width, bgImage.size.height)];

3. Draw the watermark in the lower right corner

UIImage *waterimage = [UIImage Imagenamed:logo];

CGFloat scale = 0.2;

CGFloat margin = 5;

CGFloat WATERW = waterImage.size.width * scale;

CGFloat waterh = waterImage.size.height * scale;

CGFloat Waterx = Bgimage.size.width-waterw-margin;

CGFloat watery = bgimage.size.height-waterh-margin;

[Waterimage Drawinrect:cgrectmake (Waterx, watery, waterw, Waterh)];

4. Get the finished UIImage object from the context

UIImage *newimage = Uigraphicsgetimagefromcurrentimagecontext ();

5. End Context

Uigraphicsendimagecontext ();

return newimage;

}

Image watermark (personal signature on Weibo image)

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.