UIImage fuzzy processing (frosted glass)

Source: Internet
Author: User

+ (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)

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.