Uiimage-helpers Network Image Blur usage
float quality =. 00001f;
float blurred =. 5f;
Nsurl *url = [Nsurl urlwithstring:@ "http://pic21.nipic.com/20120614/10230657_130343324168_2.jpg " ]; *data = [[NSData Alloc]initwithcontentsofurl:url]; *img = [[UIImage alloc]initwithdata:data]; *imagedata = uiimagejpegrepresentation (img, quality); = [[UIImage imagewithdata:imagedata] blurredimage:blurred];
// // uiimage+blur.h<UIKit/UIKit.h><Accelerate/Accelerate.h> <QuartzCore/QuartzCore.h>@interface UIImage (Blur)// 0.0 to 1.0-(uiimage*) Blurredimage: (cgfloat) bluramount; @end
////UIIMAGE+BLUR.M#import"Uiimage+blur.h"@implementation UIImage (Blur)-(uiimage*) Blurredimage: (cgfloat) bluramount{if(Bluramount <0.0|| Bluramount >1.0) {Bluramount=0.5; } intBoxsize = (int) (Bluramount * +); Boxsize= boxsize-(boxsize%2) +1; Cgimageref img=Self . Cgimage; Vimage_buffer Inbuffer, Outbuffer; Vimage_error Error; void*Pixelbuffer; Cgdataproviderref Inprovider=Cgimagegetdataprovider (IMG); Cfdataref Inbitmapdata=Cgdataprovidercopydata (Inprovider); Inbuffer.width=cgimagegetwidth (IMG); Inbuffer.height=cgimagegetheight (IMG); Inbuffer.rowbytes=Cgimagegetbytesperrow (IMG); Inbuffer.data= (void*) cfdatagetbyteptr (inbitmapdata); Pixelbuffer= malloc (Cgimagegetbytesperrow (IMG) *cgimagegetheight (IMG)); 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) {Error= vimageboxconvolve_argb8888 (&outbuffer, &inbuffer, NULL,0,0, Boxsize, Boxsize, NULL, kvimageedgeextend); } if(Error) {#ifdef DEBUG NSLog (@"%s Error:%zd", __pretty_function__, error);#endif returnSelf ; } cgcolorspaceref colorspace=Cgcolorspacecreatedevicergb (); Cgcontextref CTX=cgbitmapcontextcreate (Outbuffer.data, Outbuffer.width, Outbuffer.height,8, Outbuffer.rowbytes, Colorspa CE, (cgbitmapinfo) kcgimagealphanoneskiplast); Cgimageref Imageref=cgbitmapcontextcreateimage (CTX); UIImage*returnimage =[UIImage Imagewithcgimage:imageref]; Cgcontextrelease (CTX); Cgcolorspacerelease (ColorSpace); Free (pixelbuffer); Cfrelease (Inbitmapdata); Cgimagerelease (IMAGEREF); returnReturnimage;} @end
[IOS Development Code]uiimage+blur network picture Blur usage