IOS makes images blurry

Source: Internet
Author: User

#import <Accelerate/Accelerate.h>

1. Initializing a picture

Uiimageview *iv = [[Uiimageview alloc]initwithframe:[uiscreen mainscreen].bounds];

[IV setimage:[self blurryimage:[uiimage imagenamed:@ "welcome_2.jpg"] [withblurlevel:0.6]];

[Self.view Addsubview:iv];

2. How to blur a picture

-(UIImage *) Blurryimage: (UIImage *) image withblurlevel: (CGFloat) Blur

{

if (Blur <0.f | | blur > 1.F)

{

Blur = 0.5f;

}

Judging exposure level

int boxsize = (int) (blur * 100);//magnification 100 after the decimal point 2 bits are valid

Boxsize = boxsize-(boxsize% 2) + 1;//If it is even odd

Cgimageref img = image. cgimage;//Get the picture pointer

Vimage_buffer inbuffer,outbuffer;//Get Buffer

Vimage_error error;//An error class, called when the paint function is called

void *pixelbuffer;

Cgdataproviderref inprovider = Cgimagegetdataprovider (IMG);//put back an array picture

Cfdataref inbitmapdata = Cgdataprovidercopydata (Inprovider);//Copy data

Inbuffer.width = Cgimagegetwidth (IMG);//Put back the width of the bitmap

Inbuffer.height = Cgimagegetheight (IMG);//Put back the height of the bitmap

inbuffer.rowbytes = Cgimagegetbytesperrow (IMG);//Calculate the byte of the bitmap

Inbuffer.data = (void*) cfdatagetbyteptr (inbitmapdata);//fill in the picture information

Pixelbuffer = malloc (Cgimagegetbytesperrow (IMG) * Cgimagegetheight (IMG));//Create a space

if (Pixelbuffer = = NULL)

{

NSLog (@ "NO pixelbuffer");

}

Outbuffer.data = Pixelbuffer;

Outbuffer.width = Cgimagegetwidth (IMG);

Outbuffer.height = Cgimagegetheight (IMG);

outbuffer.rowbytes = Cgimagegetbytesperrow (IMG);

Error = vimageboxconvolve_argb8888 (&inbuffer, &outbuffer, NULL, 0, 0, boxsize, boxsize, NULL, Kvimageedgeextend) ;

if (Error)

{

NSLog (@ "%zd", error);

}

Cgcolorspaceref colorspace = Cgcolorspacecreatedevicergb ();

Cgcontextref CTX = cgbitmapcontextcreate (Outbuffer.data, Outbuffer.width, Outbuffer.height, 8, OutBuffer.rowBytes, ColorSpace, Kcgimagealphanoneskiplast);

Cgimageref imageref = Cgbitmapcontextcreateimage (CTX);

UIImage *returnimage = [UIImage imagewithcgimage:imageref];

Cgcontextrelease (CTX);

Cgcolorspacerelease (ColorSpace);

Free (pixelbuffer);

Cfrelease (Inbitmapdata);

Cgcolorspacerelease (ColorSpace);

Cgimagerelease (IMAGEREF);

return returnimage;

}

IOS makes images blurry

Related Article

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.