アプリケーションに画像をバンドルしたい。イメージをドローアブルまたは raw フォルダーに保持する予定です。File
この画像のオブジェクトの作り方を知りたいですか?
このようなもの:
File file = new File("fileurl");
ありがとうございました。
アプリケーションに画像をバンドルしたい。イメージをドローアブルまたは raw フォルダーに保持する予定です。File
この画像のオブジェクトの作り方を知りたいですか?
このようなもの:
File file = new File("fileurl");
ありがとうございました。
これを試してもらえますか?
try {
File mFile=new File("my file name");
InputStream inputStream = getResources().openRawResource(R.drawable.ic_launcher);
OutputStream out=new FileOutputStream(mFile);
byte buf[]=new byte[1024];
int len;
while((len=inputStream.read(buf))>0)
out.write(buf,0,len);
out.close();
inputStream.close();
}catch (Exception e){
e.printStackTrace();
}
これがあなたを助けることを願っています。
ワークスペース内のフォルダー内に画像リソースを配置するRaw
と、次を使用してクラス内でアクセスできます。
getResources.openRawResources(R.raw.resource_id)
編集 :
上記のコードは を返しinputStream
ます。ファイルに変換するには、これを試してください。
inputStream = getResources.openRawResources(R.raw.resource_id)`
// write the inputStream to a FileOutputStream
File file = new File("fileurl");
outputStream = new FileOutputStream(file);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
outputStream.close();
inputStream.close();