gpt4 book ai didi

android - 如何将图像从 drawable 传输到 sdcard 中的文件夹?

转载 作者:行者123 更新时间:2023-11-29 18:07:48 25 4
gpt4 key购买 nike

有没有办法将图像从 res/drawable 文件夹传输到 sdcard 中的文件夹?仍然了解图片的质量和细节?

最佳答案

你必须使用 BitmapFactory.decodeResource() ,通过将项目的资源 ID 传递给它,首先生成一个 Bitmap

Bitmap myBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.mybitmap);

然后,您可以使用 answer in this thread 将其保存到存储卡中.

像这样:

try {
FileOutputStream out = new FileOutputStream(filename);
myBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}

注意:@RaghavSood 在他的评论中是正确的;你真的没有理由需要这样做。您可以在运行时加载可绘制资源,而不是占用存储卡上的空间。

关于android - 如何将图像从 drawable 传输到 sdcard 中的文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12499288/

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