Skip to first unread message

Stefan Z

unread,
Dec 17, 2014, 8:40:07 AM12/17/14
to mitappinv...@googlegroups.com
I made an app which can either load and store an image by taking a picture with the camera, or by selecting it using ImagePicker (see attached image 1).
Now, I would like to find out the size (width and height) of this picture before using it as a background for a canvas in the next screen.

Since the canvas just stretches the image to fit the canvas size, I would like to find the size (or aspect ratio) of the imported image. 
Is there a direct way to find this size (I think ImagePicker only saves a path)? I could not find this and therefore tried some other ways.

I've tried to add an extra screen, display the image here using fill parent for width and automatic for height (see attached image 2). I used two labels to show the found values. However, when using Image1.height it would return the value = 0, while Image.width would give me a normal number (320 I think). The image had the correct aspect ratio in this case, visually at least, however the height could not be determined. Therefore, this didn't work either to find the aspect ratio. I have only tried this with the ImagePicker since I could not take an appropriate picture to test the app with.

Does anyone know a way to find the image size/aspect ratio for an image that I've selected with ImagePicker?

Thanks in advance.
tinydb image size.jpg
tinydb image size2.jpg

Mark Eisenhardt

unread,
Jan 23, 2015, 10:08:31 AM1/23/15
to mitappinv...@googlegroups.com
I have the exact same question and used very similar methods to try to get the image aspect ratio. We need to know how to make the canvas size fit the imagepicker.selected image nicely.

SteveJG

unread,
Jan 23, 2015, 10:19:53 AM1/23/15
to mitappinv...@googlegroups.com
You probably can determine the aspect ratio for images produced with your camera but not necessarily for ANY image picked with the image picker.  Why?
The dimensions of your camera images probably are consistent for the same device.  If you use a file app on your device and find an image taken by your camera, the dimensions for that image should be the same for all images taken with your camera?     You have a W and a H, set your Canvas to those dimensions.

However, other images on your device most certainly have other aspect ratios; the dimensions may be very different from what your camera takes and which you can determine by inspection.  An AI app can not determine the H and W of an images automatically.

Experiment with your camera images.   They should be consistent in aspect ration and you should be able to figure them out.   Can you?  Once you know them, you can work with your camera's images but not with other images.    Need to do that?   Eclipse / Android Studio etc. have image manipulation routines; AI2 does not.

Regards,
Steve
Reply all
Reply to author
Forward
0 new messages