public static String imagePath(Context context, int id) {
String imagename = "images";
String filename = Environment.getExternalStorageDirectory()
+ File.separator + imagename;
String imagePath = filename + ".jpg";
File file = new File(imagePath);
try {
if (!file.exists()) {
file.createNewFile();
}
Bitmap pic = BitmapFactory.decodeResource(context.getResources(), id);
FileOutputStream fos = new FileOutputStream(file);
pic.compress(CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch(Throwable t) {
t.printStackTrace();
imagePath = null;
}
return imagePath;
}
转载于:https://my.oschina.net/meetthebetteryour/blog/655310