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