IOS image processing-blur image

Source: Internet
Author: User

Fix the problem: blur the image

premise: add Coregraphics.framework

Source:

-(uiimage*) Blur: (uiimage*) theimage{//Create our blurred image cicontext *context = [Cicontext contextwithoptions    : nil];        Ciimage *inputimage = [Ciimage imageWithCGImage:theImage.CGImage]; Setting up Gaussian Blur (could with one of many filters offered by Core Image) cifilter *blurfilter = [Cifilter filt    erwithname:@ "Cigaussianblur"];    [Blurfilter setvalue:inputimage Forkey:kciinputimagekey];    [Blurfilter setvalue:[nsnumber numberwithfloat:10.0f] forkey:@ "Inputradius"];        Ciimage *result = [Blurfilter Valueforkey:kcioutputimagekey]; Cigaussianblur have a tendency to shrink the image a little and//This ensures it matches up exactly to the bounds of O        ur original image cgimageref cgimage = [Context Createcgimage:result fromrect:[inputimage extent];    UIImage *returnimage = [UIImage imagewithcgimage:cgimage]; Create a UIImage for this function to "return" so the ARC can manage the memory of the blur ...//arc can ' t manage CG Imagerefs so We need to release it before this function "returns" and ends.        Cgimagerelease (cgimage);//release cgimageref because ARC doesn ' t manage this in its own. return returnimage;}
A problem occurred:Because the edges become translucent at the time of blurring, the ideal condition is to enlarge the original image appropriately, choosing to use Ciaffineclamp to process the image before blurring.

Source:

-(uiimage*) Blur: (uiimage*) theimage{//Create our blurred image cicontext *context = [Cicontext contextwithoptions    : nil];        Ciimage *inputimage = [Ciimage imageWithCGImage:theImage.CGImage];    Cifilter *affineclampfilter = [Cifilter filterwithname:@ "Ciaffineclamp"];    Cgaffinetransform xform = Cgaffinetransformmakescale (1.0, 1.0);    [Affineclampfilter setvalue:inputimage Forkey:kciinputimagekey]; [Affineclampfilter setvalue:[nsvalue valuewithbytes:&xform Objctype: @enc        Ode (Cgaffinetransform)] forkey:@ "Inputtransform"];        Ciimage *extendedimage = [Affineclampfilter Valueforkey:kcioutputimagekey]; Setting up Gaussian Blur (could with one of many filters offered by Core Image) cifilter *blurfilter = [Cifilter filt    erwithname:@ "Cigaussianblur"];    [Blurfilter setvalue:extendedimage Forkey:kciinputimagekey]; [Blurfilter Setvalue:[nsnumber numberwithfloat:10.0F] forkey:@ "Inputradius"];        Ciimage *result = [Blurfilter Valueforkey:kcioutputimagekey]; Cigaussianblur have a tendency to shrink the image a little and//This ensures it matches up exactly to the bounds of O        ur original image cgimageref cgimage = [Context Createcgimage:result fromrect:[inputimage extent];    UIImage *returnimage = [UIImage imagewithcgimage:cgimage]; Create a UIImage for this function to "return" so the ARC can manage the memory of the blur ...//arc can ' t manage CG    Imagerefs so we need-release it before this function "returns" and ends.        Cgimagerelease (cgimage);//release cgimageref because ARC doesn ' t manage this in its own. return returnimage;}

Reference: (online resources, some links have been lost)

Http://stackoverflow.com/questions/12839729/correct-crop-of-cigaussianblur

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.