Perfect solution ScrollView screenshot image Blur

Source: Internet
Author: User

Uigraphicsbeginimagecontext

First explain the difference between uigraphicsbeginimagecontextwithoptions and Uigraphicsbeginimagecontext:

1:uigraphicsbeginimagecontext (cgsize size)

The size of the parameter is the newly created bitmap context. It is also the size of the graph returned by the Uigraphicsgetimagefromcurrentimagecontext function.

The function is the same as the function of uigraphicsbeginimagecontextwithoptions, quite with the uigraphicsbeginimagecontextwithoptions The opaque parameter is noand the scalefactor is 1.0.

2 uigraphicsbeginimagecontextwithoptions

The function prototypes are:

void Uigraphicsbeginimagecontextwithoptions (cgsize size, BOOL opaque, cgfloat scale);

size--with Uigraphicsbeginimagecontext

opaque-Transparent switch, if the graphic is not transparent at all, set to Yes to optimize the storage of the bitmap.

scale-– Scaling Factor

In particular, when the zoom factor is 0.0, the picture is not blurred

Screen Cutting

-(UIImage *) Capturescrollview: (Uiscrollview *) scrollview{

uiimage* image = Nil;

Uigraphicsbeginimagecontext (scrollview.contentsize); Default

Uigraphicsbeginimagecontextwithoptions (Scrollview.contentsize, NO, 0.0);

{

Cgpoint savedcontentoffset = Scrollview.contentoffset;

CGRect savedframe = scrollview.frame;

Scrollview.contentoffset = Cgpointzero;

Scrollview.frame = CGRectMake (0, 0, scrollView.contentSize.width, scrollView.contentSize.height);

[Scrollview.layer Renderincontext:uigraphicsgetcurrentcontext ()];

Image = Uigraphicsgetimagefromcurrentimagecontext ();

Scrollview.contentoffset = Savedcontentoffset;

Scrollview.frame = Savedframe;

}

Uigraphicsendimagecontext ();

if (image = nil) {

return image;

}

return nil;

}

Perfect solution ScrollView screenshot image Blur

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.