gpt4 book ai didi

java - 如何使用 BitmapFactory 加载图像文件但不是原始大小(缩小它)

转载 作者:行者123 更新时间:2023-12-01 22:20:39 25 4
gpt4 key购买 nike

所以我正在使用这段代码

Bitmap myBitmap = BitmapFactory.decodeFile(fname);

加载图像文件。但有时加载的图像可能很大,如 512x512,我现在不想加载图像的所有 262144 像素,而是加载按比例缩小的图像。我该怎么做?

最佳答案

像这样使用 Bitmap.compress() :

Uri uri = Uri.fromFile(file);
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, QUALITY, stream);

质量参数:

int: Hint to the compressor, 0-100. 0 meaning compress for small size, 100 meaning compress for max quality. Some formats, like PNG which is lossless, will ignore the quality setting

关于java - 如何使用 BitmapFactory 加载图像文件但不是原始大小(缩小它),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58593302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com