Change the frame or size of GPUImage
Hi, i'm trying to change the size of the screen.. but i'm going crazy, always see the same size of the frame. I have tried CGRect mainScreenFrame = CGRectMake(50,50,200,200); and no change the frame. I have tried to create a new uiview that contains the GPUImageView and use it with overlayView of the main uiview or making a new uiview in storyboard.
And how i can make [self.view addSubiew:primaryView]; because i did this instead of self.view = primayView; and dont show the GPUImageView.
-(void)loadView
{
CGRect mainScreenFrame = [[UIScreen mainScreen] bounds];
primaryView = [[GPUImageView alloc] initWithFrame:mainScreenFrame];
primaryView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view = primaryView;
}
Help me !!! :( Thanks
I have change the last line in GPUImageView.m class
- (void)setDisplayFramebuffer;
{
if (!displayFramebuffer)
{ [self createDisplayFramebuffer]; }
glBindFramebuffer(GL_FRAMEBUFFER, displayFramebuffer);
glViewport((GLint)20, (GLint)180, (GLint)180, (GLint)250);
}
Are you asking how to resize a GPUImageView for display? To do this, simply change its frame like you would any other view. Don't screw with the viewport settings, because that will mess up the way that content is actually rendered within the view.
Yes, i have tried but why when i do this... dont load my View and all screen is black
.h -> http://pastie.org/4048472 .m-> http://pastie.org/4048473
Fix it !!!!
- (void)loadView
{
CGRect mainScreenFrame = [[UIScreen mainScreen] bounds];
CGRect cameraFrame = CGRectMake(-120, 20, 150, 150);
viewNew = [[UIView alloc] initWithFrame:mainScreenFrame];
viewNew.backgroundColor = [UIColor redColor];
viewCamera = [[UIView alloc] initWithFrame:cameraFrame];
viewCamera.backgroundColor = [UIColor blackColor];
primaryView = [[GPUImageView alloc] initWithFrame:cameraFrame];
primaryView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[primaryView setFillMode:kGPUImageFillModeStretch];
viewCamera = primaryView;
[viewNew addSubview:viewCamera];
self.view = viewNew;
}
the width is compression,do you dealwith the problem?
Changing the frame of GPUImageView causes distortion, it should instead re-draw with the new aspect ratio
The problem with this object is that inputImageSize is NaN when it goes to calculate the aspect ratio with a fixed image. Even setting it absolutely works correctly for the first run through, then the object re-assigns the inputImageSize to be the same size as the content rect, and that causes the input image to be unevenly scaled to stretch and fill the view.
It's an active problem so I don't know why this was marked closed. Aspect Ratio doesn't work for still images basically.
Here's my super hacky quick fix. It probably breaks something else, I don''t know.
-
@property(nonatomic,assign) CGSize inputImageSize; ... add this to the interface, and set it before you set the fillMode or the input image, the value should come from your inputImage's size.
-
absolutely make sure you set fillMode after everything else as setting fillMode triggers a bunch of other stuff.
-
setInpuSize:atIndex: in GPUImageView has to return without altering inputImageSize ... this will probably break the video stuff.
-
The aspect ratio calculation is incorrect and needs to be replaced with:
case kGPUImageFillModePreserveAspectRatio: {#if 0 widthScaling = insetRect.size.width / currentViewSize.width; heightScaling = insetRect.size.height / currentViewSize.height; #else CGFloat a = currentViewSize.width / _inputImageSize.width; CGFloat b = currentViewSize.height / _inputImageSize.height; if (b < a) { widthScaling = b/a; heightScaling = 1; } else { heightScaling = a/b; widthScaling = 1; } #endif }; break;
These four fixed it for me but I'm only working with still images and I don't know what the rest of the impact is. There may be a simpler way but I dunno.
still would love a fix for this! (re-opened since aug 27). seems like @dbquarrel has a nice start!
Any advances in this old issue?
Additionally it looks should be animated without distortion.