BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.25k stars 4.61k forks source link

Cropfilter, aspect ratio madness #548

Closed Genhain closed 12 years ago

Genhain commented 12 years ago

Okay so i have been trawling the forums now for a bit And I am heaps confused on how to proceed. What i am attempting to do is thus. The player is presented with a live preview feed in which they can select filters onto it from there they can then adjust the image output with panning zooming etc. The little detail here is that i have the preview layer being of size 360x480 but i only display a portion of the preview layer though a 300_300 view The issue comes from I think my previous use of AVCaptureSessions, sometimes the preview and the picture output were inconsistent or not the same aspect ratio when i tried to make the preview be 300_300 rather than it's current 360*480. This is fine if i could get cropping to work, and i have been faffing about with the GPUImageCropfilter for a bit now and for the life of me cannot get it to produce a crop window of CGRect 160,195,300,300 i assumed to get the correct normalized coordinates it would go like

float percentageX = cropView.frame.origin.x / self.view.frame.size.width; 
float percentageY = cropView.frame.origin.y / self.view.frame.size.height;
float percentageWidth = cropView.frame.size.width / self.view.frame.size.width;
float percentageHeight = cropView.frame.size.height / self.view.frame.size.height;

and then while trawling for some help i came across brad saying the following

"Rather than having to deal with cropping the image for display, I've now added the fillMode property to GPUImageView. This lets you have the view either stretch the image to fill and ignore the aspect ratio, fit the image within the view and preserve the aspect ratio, or zoom to fill the view while preserving the aspect ratio.

This should make it a lot easier to do what you were trying here."

does this mean i can abandon the 360*480 GPUIView size and get a proper image out of it when i take the picture?

See unfortunately the stipulations of the picture that have been demanded of me are a square image of 600*600 pixels or something similiar

so yes any suggestions and or help would be greatly appreciated.

EDIT: I almost forgot as an extra constraint the image will more than likely have to stay at 360*480 or at least larger than the crop window so they can move the image about slightly to crop what they desire.

Genhain commented 12 years ago

I don't know if anyone is interested in this as it seems no one replied, but I used a different cropping method rather than a filter i basically use the gpuimage as before to get me my image then take a screenshot of the entire phone then crop the area i want...and as a knock on effect the use of gpuimage is slightly more stable as it is a smaller image...not entirely without bugs but hey ho