博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS实现图像素描效果
阅读量:6544 次
发布时间:2019-06-24

本文共 2036 字,大约阅读时间需要 6 分钟。

  使用GPUImageSketchFilter对象实现图像素描效果

NSString *const kGPUImageSketchFragmentShaderString = SHADER_STRING( precision mediump float;  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;  uniform float edgeStrength; uniform sampler2D inputImageTexture;  void main() {     float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;     float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;     float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;     float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;     float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;     float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;     float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;     float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;     float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;     float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;          float mag = 1.0 - (length(vec2(h, v)) * edgeStrength);          gl_FragColor = vec4(vec3(mag), 1.0); });
+ (UIImage *)applySketchFilter:(UIImage *)image{    GPUImageSketchFilter *filter = [[GPUImageSketchFilter alloc] init];        [filter forceProcessingAtSize:image.size];    GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:image];    [pic addTarget:filter];    [pic processImage];    [filter useNextFrameForImageCapture];        return [filter imageFromCurrentFramebuffer];}

  

 

转载地址:http://drodo.baihongyu.com/

你可能感兴趣的文章
XDebug 教程
查看>>
js 去html 标签
查看>>
好久不见
查看>>
小tips:JS中的children和childNodes
查看>>
二叉树的遍历
查看>>
Oracle的FIXED_DATE参数
查看>>
PostgresSQL中的限制和级联删除
查看>>
NDK配置
查看>>
(转)@ContextConfiguration注解说明
查看>>
docker in centos error
查看>>
c# 线程同步: 详解lock,monitor,同步事件和等待句柄以及mutex
查看>>
[置顶] ※数据结构※→☆线性表结构(queue)☆============队列 顺序存储结构(queue sequence)(八)...
查看>>
Log4perl 的使用
查看>>
Linux 系统的单用户模式、修复模式、跨控制台登录在系统修复中的运用
查看>>
《http权威指南》阅读笔记(十)
查看>>
JQuery UI Widget Factory官方Demo
查看>>
Atlas揭秘 —— 绑定(Binding)
查看>>
install xcode_3.2.5_and_iOS_sdk_4.2 _final with mac lion10.7.3
查看>>
JavaScript权威指南(第6版)
查看>>
sql 自定義百分比轉換小數函數
查看>>