1

我想将图像从 Drawable 文件夹存储到 Android 中的 SDCard。我尝试了很多,但找不到解决方案。请有人帮我解决这个问题。谢谢。

4

1 回答 1

1

这些drawable文件夹中的图片可以通过BitmapFactory访问,你可以将位图保存为PNG或JPG。

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    File sd = Environment.getExternalStorageDirectory();
    String fileName = "test.png";
    File dest = new File(sd, fileName);
    try {
        FileOutputStream out;
        out = new FileOutputStream(dest);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

对于其他类型的图像,我认为将它们放入 assets 文件夹是一种更好的方法。

于 2012-11-28T04:32:59.943 回答