开发者

Android, Copy .png file form res.raw to App's private internal memor

开发者 https://www.devze.com 2023-02-04 21:50 出处:网络
I need to copy a PNG file form res.raw my App\'s private internal memory. This is code I am using. The resulting file appears to be corrupt in that BitmapFactory.decodeFile() returns null. The same fi

I need to copy a PNG file form res.raw my App's private internal memory. This is code I am using. The resulting file appears to be corrupt in that BitmapFactory.decodeFile() returns null. The same file, if placed on the SD Card decodes just fine. Here is the code that I am using.

private void loadGraphics(){
    InputStream inputStream = BasicContext.getResources().openRawResource(R.raw.galaxy);
    InputStreamReader inputreader = new InputStreamReader(inputStream);
    BufferedReader buf开发者_高级运维freader = new BufferedReader(inputreader, 8192);

     int Byte = 0;
     FileWriter writer = null;
   String PathA = "/sdcard/rfo-basic/data/Galaxy1.png";
     try {
      writer = new FileWriter(PathA);
      do {
      Byte = buffreader.read();
      {writer.write(Byte);}
      } while (Byte != -1);

     } catch (IOException e) {
       Log.v(Basic.LOGTAG, " " + Basic.CLASSTAG + " I/O Exception 2 ");
     }
     finally {
if (writer != null) {
 try {
  writer.flush();
  writer.close();
 } catch (IOException e) {
          Log.v(Basic.LOGTAG, " " + Basic.CLASSTAG + " I/O Exception 4 ");
 }
}
     }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消