Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

bitmap - Android how to scale an image with BitmapFactory Options

I want to decode an image from the SD card with BitmapFactory.decodeFile(path, options).
I also want images that are larger than 2048x2048 pixels to be scaled down to at most 2048x2048 (maintaining the proportions).
I could do this manually after getting the bitmap, but that would require allocating a large amount of bytes in addition to the ones already allocated.
How should i set up my BitmapFactory.Options object to get that effect?
Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use BitmapFactory.Options.inSampleSize when you first load your image to get the size as close as possible to your target size, then use Bitmap.createScaledBitmap to scale to the exact size you want.

There's some code for this in this answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...