iOS gives the picture a water stamp and creates a watermark image into the sandbox

Source: Internet
Author: User

-(void) waterimage
{
UIImage *bgimage = [UIImage imagenamed:@ "scene"];

Context: Bitmap-based (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];
}

iOS gives the picture a water stamp and creates a watermark image into the sandbox

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.