This is in a way the reverse scenario to the following excellent tutorial from Rob :
http://coronalabs.com/blog/2014/06/10/tutorial-fitting-images-to-a-size/
My question is, how can I save a display object from varying devices and end up with an identically sized jpg or png file on my device (more on that need later…).
I am using some excellent information shared by @schroederapps and @Renato in the following thread to create an circular avatar.
http://forums.coronalabs.com/topic/48985-how-can-i-implement-this-function/
Won’t repeat the code here as it can easily be seen in the thread linked above but in summary, I create a circle with a radius of 120 and fill it with a camera image and then save it to device using display.save().
On an iPad I end up with a 512x512 file. On iPhone the file ends up being 480x480. On many Android devices I will end up with many different sizes…
In order to use the Avatar with various backend services, I need it to be a fixed size conforming to the demands of the service in question. I am hoping to be able to therefore control the size of the final file saved.
Possible Strategies
a ) Identify device DPI and do math to determine what ‘120’ (circle radius) equate to in pixels and then do some scaling on the display object before saving it so that the final output is a fixed size regardless of device.
Challenge with this one is the Android device variability and the fact that I can’t always get a reliable DPI reading off the device…
b ) Save in whatever size display.save ends up providing and then use a backend service to do some resizing magic.
Challenge with this one is additional transfer time & process complexity. I’d rather keep all pre-processing on device if at all possible.
What am I missing? Is there an option c, d, e and maybe even f? How would you tackle this challenge?
Thanks in advance for your help. Wishing you all a great weekend.
Regards,
Kerem