[英]How to create an image file from drawable path
大家好,我是一名Android开发人员,我正在尝试从可绘制资源创建图像文件,如下所示:
Bitmap btm = BitmapFactory.decodeResource(getResources(),R.drawable.image1);
Bitmap btm = BitmapFactory.decodeFile(pathname);
btm.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory()+ File.separator + "temporary_file.jpg");
try {
f.createNewFile();
new FileOutputStream(f).write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
但是我需要从image1的路径开始创建文件,我尝试使用:
String pathname = currentLevel.getImagePath();
Bitmap btm = BitmapFactory.decodeFile(pathname);
btm.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
但这不起作用:
E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: android.resource:/com.example.utente.guessimageferes/drawable/immagine1 (No such file or directory)
也有
String pathname ="android.resource://com.example.utente.guessimageferes/drawable/immagine1"
我有同样的问题,有可能使我想要吗?
我需要的是从image1的路径开始
没有通往image1
路径。 image1
是资源。 它是开发计算机上的文件。 它不是设备上的文件。 因此,它没有路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.