我希望我的GPUImageView(人像,前置摄像头)无论手机屏幕尺寸如何都是全屏的(从iPhone 4到Iphone 6+)。理想情况下遵循" Aspect填充"模式。
现在我有:
_vidCamera = [[GPUImageVideoCamera alloc]
initWithSessionPreset:AVCaptureSessionPreset640x480
cameraPosition:AVCaptureDevicePositionBack];
_vidCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
// View
CGRect f = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
_filteredVideoView = [[GPUImageView alloc] initWithFrame:f];
kGPUImageFillModeStretch会不够?我是否还需要更改SessionPreset?如果我将会话预设更改为比iPhone 4可以处理的更大的东西,它会引起麻烦吗?
很抱歉,我无法亲自测试,因为我不仅仅拥有iPhone 4。
答案 0 :(得分:3)
源代码中有3种模式。
public var kGPUImageFillModeStretch: GPUImageFillModeType { get }
// Stretch to fill the full view, which may distort the image outside of its normal aspect ratio
public var kGPUImageFillModePreserveAspectRatio: GPUImageFillModeType { get }
// Maintains the aspect ratio of the source image, adding bars of the specified background color
public var kGPUImageFillModePreserveAspectRatioAndFill: GPUImageFillModeType { get }
// Maintains the aspect ratio of the source image, zooming in on its center to fill the view
在我看来,最好使用 kGPUImageFillModePreserveAspectRatioAndFill 。使用拉伸选项会导致奇怪的输出。
将fillMode设置为GPUImageFilter:
filterView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill