1 /**2 * Blur Background3 *4 * @param image requires a blurred image5 * @param blur Gaussian blur value6 *7 * @return8 */9-(UIImage *) Blurryimage: (UIImage *) Image withblurlevel: (cgfloat) BlurTen { One if((Blur <0.0f) || (Blur >1.0f)) { ABlur =0.5f; - } - the intBoxsize = (int) (Blur * -); -Boxsize-= (boxsize%2) +1; - -Cgimageref img =image. Cgimage; + - Vimage_buffer Inbuffer, Outbuffer; + Vimage_error Error; A void*Pixelbuffer; at -Cgdataproviderref Inprovider =Cgimagegetdataprovider (IMG); -Cfdataref Inbitmapdata =Cgdataprovidercopydata (inprovider); - -Inbuffer.width =cgimagegetwidth (IMG); -Inbuffer.height =cgimagegetheight (IMG); inInbuffer.rowbytes =Cgimagegetbytesperrow (IMG); -Inbuffer.data = (void*) cfdatagetbyteptr (inbitmapdata); to +Pixelbuffer = malloc (Cgimagegetbytesperrow (IMG) *cgimagegetheight (IMG)); - theOutbuffer.data =Pixelbuffer; *Outbuffer.width =cgimagegetwidth (IMG); $Outbuffer.height =cgimagegetheight (IMG);Panax NotoginsengOutbuffer.rowbytes =Cgimagegetbytesperrow (IMG); - theError = vimageboxconvolve_argb8888 (&inbuffer, &outbuffer, NULL,0,0, Boxsize, Boxsize, NULL, kvimageedgeextend); + ACgcolorspaceref ColorSpace =Cgcolorspacecreatedevicergb (); theCgcontextref CTX = cgbitmapcontextcreate (Outbuffer.data, Outbuffer.width, Outbuffer.height,8, Outbuffer.rowbytes, ColorSpace, Cgimagegetbitmapinfo (image. Cgimage)); + -Cgimageref Imageref =cgbitmapcontextcreateimage (CTX); $UIImage *returnimage =[UIImage imagewithcgimage:imageref]; $ - // Clean Up - cgcontextrelease (CTX); the cgcolorspacerelease (colorspace); - Wuyi Free (pixelbuffer); the cfrelease (inbitmapdata); - Wu cgcolorspacerelease (colorspace); - cgimagerelease (imageref); About $ returnReturnimage; -}
IOS view Blur Background