Crop pictures, screenshots, save to albums, watermarks

Source: Internet
Author: User

--- crop a circular picture

- draw a round head with a border

-(void) Touchesbegan: (nsset*) touches withevent: (uievent*) event

{

//-1. Get Pictures

uiimage* image = [UIImage imagenamed:@ "Me"];

// -2.margin

CGFloat margin = ten;

//-3. Context Size

Cgsize size = Cgsizemake (Image.size.width + 2 * margin, image.size.height + 2 * margin);

//-4. Open Picture Context

Uigraphicsbeginimagecontextwithoptions (Size, NO, 0);

//-5. Get the graphics context

Cgcontextref CTX = Uigraphicsgetcurrentcontext ();

//-6. Center Center

Cgpoint arccenter = Cgpointmake (size.width * 0.5, size.height * 0.5);

//-7. radius

CGFloat radius = image.size.width * 0.5 + margin * 0.5;

//-8. Draw Border

Cgcontextaddarc (CTX, arccenter.x, arccenter.y, radius, 0, 2 * m_pi, 1);

//-9. Set width

Cgcontextsetlinewidth (CTX, margin);

//-10. Render Border

Cgcontextstrokepath (CTX);

//-11. Draw the area you want to crop

Cgcontextaddarc (CTX, arccenter.x, Arccenter.y, Image.size.width * 0.5, 0, 2 * m_pi, 1< c15>);

//-12. cropping

Cgcontextclip (CTX);

//-13. Picture Portrait

[Image drawatpoint:cgpointmake (margin, margin)];

//-14. gets the current image

Image = Uigraphicsgetimagefromcurrentimagecontext ();

//-15. Close Picture Context

Uigraphicsendimagecontext ();

//-16. Assign Value

self. imageview.image = image;

}

Save to album

First : picture

the second third listener Note : @selector can not write casually using the " comments " method

Fourth : It can be used as a tag to use parameters in the listening method will be passed in

Uiimagewritetosavedphotosalbum (NewImage, self, @selector(image:didfinishsavingwitherror: ContextInfo:), @ "hello1111");

--- screen

to manipulate the Layer property of a controller's view

[self. View.layer Renderincontext:ctx];

-(void) Touchesbegan: (nsset*) touches withevent: (uievent*) event

{

// Open Picture context

Uigraphicsbeginimagecontextwithoptions (selfview.bounds.size, NO, 0);

// Gets the current picture context

Cgcontextref CTX = Uigraphicsgetcurrentcontext ();

//

[self. View.layer Renderincontext:ctx];

// take pictures

uiimage* image = Uigraphicsgetimagefromcurrentimagecontext ();

// off

Uigraphicsendimagecontext ();

// save to album

Uiimagewritetosavedphotosalbum (image, nil, nil, nil);

}

//0. Watermark

-(void) Touchesbegan: (nsset*) touches withevent: (uievent*) event

{

//Water printing

// Get a picture that requires a watermark

uiimage* image = [UIImage imagenamed:@ "HHKB"];

// Open the context of the picture type

Uigraphicsbeginimagecontextwithoptions (image.size, NO, 0);

// draw a picture of the watermark to the context

[Image Drawatpoint:cgpointzero];

// text watermark content

nsstring* str = @ " Preach Wisdom Podcast IOS";

// draw text at the same time set some parameters of the text

[Str drawatpoint:cgpointmake ( withattributes):@{ nsfontattributename: [Uifont Systemfontofsize:+], nsforegroundcolorattributename: [Uicolor whitecolor] };

// picture watermark content

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

// picture watermark

[Logo drawatpoint:cgpointmake (Image.size.width- $ - image.size.height - )];

// get pictures

Image = Uigraphicsgetimagefromcurrentimagecontext ();

// Close context

Uigraphicsendimagecontext ();

// save to album

Uiimagewritetosavedphotosalbum (image, nil, nil, nil);

}

Crop pictures, save to albums, Watermark

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.