[英]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.