0

I have pictures/images in my drawable folder and I want to copy all of it in my sdcard folder with that same quality and details? If I have for example this.

Integer[] mThumbIds = {
        R.drawable.pic_1, R.drawable.pic_2,
        R.drawable.pic_3, R.drawable.pic_4,
        R.drawable.pic_5, R.drawable.pic_6,
        R.drawable.pic_7
};

And then my app creates an own directory in sdcard, like this:

String newFolder = "/myFolder2";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File myNewFolder = new File(extStorageDirectory + newFolder);
myNewFolder.mkdir();

How can I achieve to transfer all those pictures in drawable to the created folder in sdcard with the same quality and details?

4

1 回答 1

3

这些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-09-20T03:05:28.163 回答