GPUImage(五):GPUImageView

GPUImageView在响应链的终点,是一个UIView,不用继承自GPUImageOutput,但实现GPUImageInput协议。

GPUImageView的接口非常简单,几乎只需设置一个GPUImageFillModeType填充模式,填充模式有三种:
在GPUImageView的frame位全屏幕,GPUImageVideoCamera比例为AVCaptureSessionPreset640x480时的效果
kGPUImageFillModePreserveAspectRatio(默认)
保持源图像的宽高比,空白部分添加设置的背景色。

Maintains the aspect ratio of the source image, adding bars of the specified background color


图片发自简书App

** kGPUImageFillModeStretch**:
拉伸使图片填满视图,可能会破坏图片的比例

Stretch to fill the full view, which may distort the image outside of its normal aspect ratio

**


图片发自简书App

kGPUImageFillModePreserveAspectRatioAndFill**:
保持源图片比例,在中心基础上缩放,图片铺满整个屏幕

Maintains the aspect ratio of the source image, zooming in on its center to fill the view

图片发自简书App

init方法

+ (Class)layerClass 
- (id)initWithFrame:(CGRect)frame
-(id)initWithCoder:(NSCoder *)coder
- (void)commonInit;
- (void)layoutSubviews;

这的初始化方法与GPUImageFilter实现类似,主要的就是调用显示帧缓存的方法。

管理显示fbos

- (void)createDisplayFramebuffer;
- (void)destroyDisplayFramebuffer;
- (void)setDisplayFramebuffer;
- (void)presentFramebuffer;

各种对帧缓存和渲染缓存的创建和销毁

处理填充模式

- (void)recalculateViewGeometry;
- (void)setBackgroundColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent;

  • 根据填充模式重新计算图像顶点位置数据
  • 设置背景色
  • 计算不同旋转模式下的纹理坐标

实现GPUImageInput代理方法

这个参照GPUImageFilter的解释

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 14日晚的油烟管道清洗无专人跟场,.,.清洗效果如何?签字负责?整改过程中工程电的专业度把控及检查。彭总的兵怎可随...
    vickysaid阅读 174评论 0 0
  • 本文参加#感悟三下乡,青春筑梦行#活动,本人承诺,文章内容为原创,且未在其他平台发表过。 我从未低估你的雄齐壮丽,...
  • 作者妙手书生 生活 生活是一列奔驰得火车 像秋风扫落叶 干净利落 有的人枕着一叶秋叶 畏手畏脚 躺在铁轨旁 有的人...
    0967655c090d阅读 372评论 3 2