iOS development: Capturing the current view

Source: Internet
Author: User

This is the function that I used when I was writing a small experiment. I pulled it out of my own.

+(UIImage *)capturImageWithUIView:(UIView *)view{    //开启位图上下文    UIGraphicsBeginImageContext(view.bounds.size);    //获取当前位图    CGContextRef ctx = UIGraphicsGetCurrentContext();    //将视图渲染到位图上    [view.layer renderInContext:ctx];    //获取当前图片    UIImage *currentImage = UIGraphicsGetImageFromCurrentImageContext();    //结束位图编辑    UIGraphicsEndImageContext();    return currentImage;}

Here's what I'm writing. Cut a square image into a circular picture and add a border.

+ (UIImage*)Cutcircleimagewithuiimage: (UIImage*)ImageWithbordercolor: (Uicolor*)ColorWithborderwidth: (cgfloat) width{CGRect imagerect = {{0,0},{Image.size. width,Image.size. Height}};//Open Bitmap contextUigraphicsbeginimagecontextwithoptions (Image.size, NO,0.0);//Get current bitmapCgcontextref CTX = Uigraphicsgetcurrentcontext ();//Specify a circle to delete the part outside the CircleCgcontextaddellipseinrect (CTX, imagerect); Cgcontextclip (CTX);//Add the picture in[ImageDrawinrect:imagerect];//Add a borderCgcontextaddellipseinrect (CTX, imagerect);    Cgcontextsetlinewidth (ctx, width); [ColorSet]; Cgcontextstrokepath (CTX);//Get current pictureUIImage*screenimage= Uigraphicsgetimagefromcurrentimagecontext ();//End Bitmap editingUigraphicsendimagecontext ();//Return the picture    returnScreenimage;}

File on cloud Disk: Https://yunpan.cn/cP98wIjYCvQAZ (extract code: 30F5)
If you have a good little functional idea, or have suggestions for my code, you can leave a comment in the comments. If you think I can write a little bit of attention, if you can please pay attention to my Weibo: Http://weibo.com/xiaopenguu each update will be updated in the microblog
Thank you for your attention.

iOS development: Capturing the current view

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.