-(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