IOS Frosted glass Effect implementation

Source: Internet
Author: User

Add blur effect, image is picture, Blur is blur degree

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

Fuzziness,

if ((Blur < 0.1f) | | (Blur > 2.0f)) {

Blur = 0.5f;

}

Boxsize must be greater than 0

int boxsize = (int) (blur * 100);

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 the C language application interface (API) for vector and matrix math, 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;

The data source provider, defines an opaque type, the 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);

Like number 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 intermediate 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 (&outbuffer2, &inbuffer, 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);

Cgimagerelease (IMAGEREF);

return returnimage;

}


IOS Frosted glass Effect implementation

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.