问题描述
我在我的文件夹绘制的图片/照片,我想这一切与相同的质量和细节复制我的SD卡文件夹?如果我有这样的例子。
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
};
然后我的应用程序中创建一个SD卡的自己的目录,如:
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();
我如何能实现在绘有相同的质量和细节传递所有图片创建的文件夹在SD卡?
How can I achieve to transfer all those pictures in drawable to the created folder in sdcard with the same quality and details?
推荐答案
在绘制文件夹中这些图像可以通过BitmapFactory访问,可以将位图保存为PNG或JPG。
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
这篇关于如何从绘制文件夹中的样本图像复制到SD卡的文件夹,programmaticaly?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!