GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

Change the frame or size of GPUImage

Open jadelmag opened this issue 14 years ago • 10 comments

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

jadelmag avatar Jun 06 '12 14:06 jadelmag

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);
}

jadelmag avatar Jun 06 '12 16:06 jadelmag

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.

BradLarson avatar Jun 07 '12 19:06 BradLarson

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

jadelmag avatar Jun 08 '12 05:06 jadelmag

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;

}

jadelmag avatar Jun 08 '12 13:06 jadelmag

the width is compression,do you dealwith the problem?

ordinary avatar Jun 30 '12 00:06 ordinary

Changing the frame of GPUImageView causes distortion, it should instead re-draw with the new aspect ratio

jjxtra avatar Nov 09 '12 15:11 jjxtra

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.

dbquarrel avatar Aug 27 '13 03:08 dbquarrel

Here's my super hacky quick fix. It probably breaks something else, I don''t know.

  1. @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.

  2. absolutely make sure you set fillMode after everything else as setting fillMode triggers a bunch of other stuff.

  3. setInpuSize:atIndex: in GPUImageView has to return without altering inputImageSize ... this will probably break the video stuff.

  4. 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.

dbquarrel avatar Aug 27 '13 04:08 dbquarrel

still would love a fix for this! (re-opened since aug 27). seems like @dbquarrel has a nice start!

taberrr avatar Sep 20 '14 15:09 taberrr

Any advances in this old issue?

Additionally it looks should be animated without distortion.

euler0 avatar Nov 30 '14 02:11 euler0