问题
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?
回答1:
These images in drawable folder can be accessed by BitmapFactory, you can save the bitmap to PNG or 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();
}
For other type of images, I think put them into assets folder is a better way.
Best Regards, Zhenghong Wang
来源:https://stackoverflow.com/questions/12505307/how-to-copy-the-sample-images-from-the-drawable-folder-to-the-sdcard-folder-pro