Scaling Jpg / Png Bitmap

vb1992

Well-Known Member
Licensed User
Longtime User
If I had the user loading Images

Chooser.Show("image/*", "Choose image")

And I wanted to scale that Image into 300 dip x 300 dip Imageview

What is the best way?

Just say the user loads a 800w X 500h photo

But you really don't know the exact size since the user is picking it.


Goal: I want to retain aspect ratio of original photo scaled down to fit inside that window
Goal2: I want to resize this bitmap so I am not working with huge files also


Thanks
 
Last edited:

Roger Garstang

Well-Known Member
Licensed User
Longtime User
May have to parse out the file header and find the width/height. I do something similar in PHP generating thumbnails, but it has more memory available. There is a function there that reads the header and reports values, but notes that it isn't accurate 100% of the time, so I ended up loading it to get the size then figuring the ratio to get the largest side within the thumbnail bounds and apply that ratio to both sides to keep it at the proper scale and not stretch. Loading may be a problem for Android memory though.
 
Upvote 0
Top