Use Gpuimagesketchfilter object to achieve image sketch effect
NSString *ConstKgpuimagesketchfragmentshaderstring =shader_string (Precision Mediumpfloat; Varying VEC2 texturecoordinate; Varying VEC2 lefttexturecoordinate; Varying VEC2 righttexturecoordinate; Varying VEC2 toptexturecoordinate; Varying VEC2 toplefttexturecoordinate; Varying VEC2 toprighttexturecoordinate; Varying VEC2 bottomtexturecoordinate; Varying VEC2 bottomlefttexturecoordinate; Varying VEC2 bottomrighttexturecoordinate; Uniformfloatedgestrength, uniform sampler2d inputimagetexture; voidMain () {floatBottomleftintensity =texture2d (Inputimagetexture, bottomlefttexturecoordinate). R; floatToprightintensity =texture2d (Inputimagetexture, toprighttexturecoordinate). R; floatTopleftintensity =texture2d (Inputimagetexture, toplefttexturecoordinate). R; floatBottomrightintensity =texture2d (Inputimagetexture, bottomrighttexturecoordinate). R; floatLeftintensity =texture2d (Inputimagetexture, lefttexturecoordinate). R; floatRightintensity =texture2d (Inputimagetexture, righttexturecoordinate). R; floatBottomintensity =texture2d (Inputimagetexture, bottomtexturecoordinate). R; floatTopintensity =texture2d (Inputimagetexture, toptexturecoordinate). R; floatH =-topleftintensity-2.0* topintensity-toprightintensity + bottomleftintensity +2.0* Bottomintensity +bottomrightintensity; floatv =-bottomleftintensity-2.0* leftintensity-topleftintensity + bottomrightintensity +2.0* Rightintensity +toprightintensity; floatMag =1.0-(Length (VEC2 (H, v)) *edgestrength); Gl_fragcolor= VEC4 (VEC3 (MAG),1.0); });
+ (UIImage *) Applysketchfilter: (UIImage *) image{ *filter = [[Gpuimagesketchfilter alloc] init]; [Filter forceProcessingAtSize:image.size]; *pic = [[Gpuimagepicture alloc] initwithimage:image]; [pic Addtarget:filter]; [pic Processimage]; [Filter usenextframeforimagecapture]; return [Filter Imagefromcurrentframebuffer];}
iOS for Image sketch effects