Proper way to handle Device rotation with GPUImagePicture?
Is there a clean way to handle device rotation when using a GPUImagePicture as the source? I have a GPUImageView that is being autoresized correctly (I have noticed that it listens for it's frame changing and when that occurs destroys the Frame buffer and recreates it). However, when the GPUImagePicture is rendered in the updated GPUImageView the resulting image is stretched incorrectly.
The only solution I've found for this is to completely destroy the entire filter chain and rebuild. But this is a sledge hammer approach and does not provide for a nice clean transition.
What is the proper way to handle this?
Have you set the fill mode on the GPUImageView to respect the aspect ratio of the input image, and not stretch it? If so, you might be able to call -processImage on the input image to have it re-render at the right size in the output view.
I have set: self.outputView.fillMode = kGPUImageFillModePreserveAspectRatio;
and then in didRotateFromInterfaceOrientation I have:
[picture processImage];
But I still get the same results, the image stretches incorrectly.
I have noticed that GPUImageView does not call recalculateViewGeometry on a device rotation (where the fillMode is used).
In GPUImageView to recalculate the vertices based on fill mode on observation of the frame changing:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (object == self && [keyPath isEqualToString:@"frame"] && (!CGSizeEqualToSize(self.bounds.size, CGSizeZero)))
{
[self recalculateViewGeometry];
[self destroyDisplayFramebuffer];
[self createDisplayFramebuffer];
}
}
This combined with a processImage call in the View Controller after an orientation change takes care of it. It still isn't a smooth rotation (i.e. the image doesn't scale while rotating, but instead pops to the correct mode after a rotation), but it seems to work.
Although this issue has not seen activity in the lately, I'd like to ask for you support or ideas to fix it.
I'm facing the same issue as @powellmark did. When rotating the device, the image in my GPUImageView gets stretched incorrectly. Everything looks good until I don't rotate the device.
fillMode is set to kGPUImageFillModePreserveAspectRatio when the GPUImageView is initialized. I'm using constraints for resizing the GPUImageView, which works fine. I also tried out if manual resizing helps, but it didn't show other results.
When debugging in GPUImageView.m, I can see that recalculateViewGeometry gets called and calculates the correct results.
I use a GPUImageFilterPipeline for filtering an array of filters. My input is a GPUImagePicture
Any ideas? Thank you. Cheers
Update: I figured out that calling processImage on GPUimagePicture manually seems to fix the squeezed image. Here's the code snippet:
- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super willTransitionToTraitCollection:newCollection
withTransitionCoordinator:coordinator];
dispatch_async(dispatch_get_main_queue(), ^{
[self.imagePicture processImage];
});
}
Cheers