2

アプリケーションに画像をバンドルしたい。イメージをドローアブルまたは raw フォルダーに保持する予定です。Fileこの画像のオブジェクトの作り方を知りたいですか?

このようなもの:

File file = new File("fileurl");

ありがとうございました。

4

2 に答える 2

1

これを試してもらえますか?

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();
      }

これがあなたを助けることを願っています。

于 2015-11-27T05:08:32.343 に答える
0

ワークスペース内のフォルダー内に画像リソースを配置する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();
于 2013-05-29T17:16:14.303 に答える