#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