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的解釋

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章