2015년 1월 4일 일요일

Find selected image size/aspect ratio

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?




댓글 없음:

댓글 쓰기