Android 如何使用 BitmapFactory 选项缩放图像 [英] Android how to scale an image with BitmapFactory Options

查看:27
本文介绍了Android 如何使用 BitmapFactory 选项缩放图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 BitmapFactory.decodeFile(path, options) 从 SD 卡解码图像.
我还希望将大于 2048x2048 像素的图像缩小到最多 2048x2048(保持比例).
我可以在获取位图后手动执行此操作,但这需要在已分配的字节之外分配大量字节.
我应该如何设置我的 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

推荐答案

使用 BitmapFactory.Options.inSampleSize 当您第一次加载图像以获得尽可能接近目标尺寸的尺寸时,然后使用 Bitmap.createScaledBitmap 缩放到精确尺寸你想要.

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.

这个答案中有一些代码.

这篇关于Android 如何使用 BitmapFactory 选项缩放图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆