How to maintain the aspect ratio when using GPUImage? -
i found instagram has camera window 300*300? square, im trying use gpuimage make same camera size.so wrote this:
primaryview = [gpuimageview alloc] initwithframe: cgrectmake(0,0,300,300)];//define square view //define still camera stillcamera = [[gpuimagestillcamera alloc] initwithsessionpreset:avcapturesessionpreset640x480 cameraposition:avcapturedevicepositionfront]; //make portrait stillcamera.outputimageorientation = uiinterfaceorientationportrait; //define filter filter = [[gpuimagefilter alloc] init]; //force output 300*300 [filter forceprocessingatsize:((gpuimageview*)self.primaryview).sizeinpixels]; //set things [stillcamera addtarget: filter]; [filter addtarget: primaryview]; [stillcamera startcameracapture];
now square view..but view looks flat, distortion, think might wrong aspect ratio.then set fill mode of primary view this:
[primaryview setfillmode:kgpuimagefillmodepreserveaspectratioandfill];
then this:
[primaryview setfillmode:kgpuimagefillmodepreserveaspectratio];
then this:
[primaryview kgpuimagefillmodestretch];
finally! none of these work..so missing, one, help.
-forceprocessingatsize:
causes filter output image of size provide, ignoring aspect ratio. squishes image 300x300 square.
if want preserve aspect ratio of image, you'd want use -forceprocessingatsizerespectingaspectratio:
.
however, letterbox image. replicate instagram does, want instead cut square region out of center of image. that, use crop filter square aspect ratio.
Comments
Post a Comment