+ (UIImage *) Accelerateblurwithimage: (UIImage *) image
{
if (image==nil)
{
NSLog(@ "error: failed to get original image when adding blur effect to picture ");
return nil;
}
// blur degree ,
if ((Blur < 0.1f) | | (Blur > 2.0f)) {
Blur = 0.5f;
// }
//boxsize must be greater than 0
int boxsize = (int) ( 5);
Boxsize-= (boxsize% 2) + 1;
NSLog(@ "boxsize:%i", boxsize);
// image processing
cgimageref img = image. Cgimage;
// need to introduce #import <Accelerate/Accelerate.h>
/*
This document describes the accelerate Framework, which contains C APIs for vector and matrix math, digital signal process ING, large number handling, and image processing.
This document describes the accelerate Framework, which contains vector and matrix math for C language application interfaces (APIs), digital signal processing, mass processing, and image processing.
*/
// image cache , input cache, output cache
vimage_buffer inbuffer, outbuffer;
vimage_error Error;
// pixel cache
void *pixelbuffer;
// data source provider,defines an opaque type this supplies Quartz with data.
cgdataproviderref inprovider = cgimagegetdataprovider(IMG);
//Provider ' s data.
cfdataref inbitmapdata = cgdataprovidercopydata(inprovider);
// width, height, byte / line,data
Inbuffer. width = cgimagegetwidth(IMG);
Inbuffer. height = cgimagegetheight(IMG);
Inbuffer. rowbytes = cgimagegetbytesperrow(IMG);
Inbuffer. Data = (void*)cfdatagetbyteptr(inbitmapdata);
//Image cache, byte line * picture high
Pixelbuffer = malloc(cgimagegetbytesperrow(IMG) * cgimagegetheight(img));
Outbuffer. data = pixelbuffer;
Outbuffer. width = cgimagegetwidth(IMG);
Outbuffer. height = cgimagegetheight(IMG);
Outbuffer. rowbytes = cgimagegetbytesperrow(IMG);
// Third middle buffer , anti-aliasing effect
void *pixelbuffer2 = malloc(cgimagegetbytesperrow(IMG) * cgimagegetheight(img));
vimage_buffer outBuffer2;
OutBuffer2. data = pixelBuffer2;
OutBuffer2. width = cgimagegetwidth(IMG);
OutBuffer2. height = cgimagegetheight(IMG);
OutBuffer2. rowbytes = cgimagegetbytesperrow(IMG);
//convolves a region of interest within an ARGB8888 source image by an implicit M x N kernel that have the effect of a Box filter.
Error = vimageboxconvolve_argb8888(&inbuffer, &outbuffer2, NULL, 0, 0, Boxsize, Boxsize, NULL, kvimageedgeextend);
Error = vimageboxconvolve_argb8888(&inbuffer, &outbuffer2, NULL, 0, 0 , Boxsize, Boxsize, NULL, kvimageedgeextend);
Error = vimageboxconvolve_argb8888(&inbuffer, &outbuffer, NULL, 0, 0, Boxsize , Boxsize, NULL, kvimageedgeextend);
if (error) {
NSLog(@ "error from convolution%ld", error);
}
//NSLog (@ " byte component:%zu", Cgimagegetbitspercomponent (IMG));
// color space devicergb
cgcolorspaceref colorspace = Cgcolorspacecreatedevicergb();
// Create context with picture , Cgimagegetbitspercomponent (IMG), 7,8
cgcontextref ctx = cgbitmapcontextcreate(
Outbuffer. data,
Outbuffer. width,
Outbuffer. height,
8,
Outbuffer. rowbytes,
ColorSpace,
cgimagegetbitmapinfo(image. Cgimage));
// based on context, processed pictures, re-assembly
cgimageref imageref = cgbitmapcontextcreateimage (CTX);
UIImage *returnimage = [UIImage imagewithcgimage: imageref];
//clean up
cgcontextrelease(CTX);
cgcolorspacerelease(colorspace);
free(pixelbuffer);
free(pixelBuffer2);
cfrelease(inbitmapdata);
//cgcolorspacerelease (colorspace); extra release.
cgimagerelease(imageref);
return returnimage;
}
UIImage fuzzy processing (frosted glass)