[IOS Development Code]uiimage+blur network picture Blur usage

Source: Internet
Author: User
Tags uikit

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

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.