开发者

Saving a BitmapDrawable or Bitmap

开发者 https://www.devze.com 2023-01-27 11:55 出处:网络
Okay, so I have a code, that take an image of the current view, and turns it into a bitmap, then I end up here,

Okay, so I have a code, that take an image of the current view, and turns it into a bitmap, then I end up here,

Bitmap bm = view.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);

now, what I'm trying to do, is take a picture of what the current view looks like, but from here, I can easily put bitmapDrawable into an ImageView, but thats not what I want, I'd like to go from here, to saving it. What can I do? I found out one way, using

FileOutputStream fos;
  try {
   fos = super.openFileOutput("output.png",MODE_WORLD_READABLE);
   bm.compress(CompressFormat.PNG, 75, fos);

      fos.flush();
      fos.close();
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
开发者_C百科

}

but when I do this, I end up with a NullPointerException at

bm.compress(CompressFormat.PNG, 75, fos);

am I missing something?

Okay, now it makes it through the above code, then makes it past fos.close(); to finish, but then nothing happens, its not saved, not on my phone, nothing


The only thing that can be null on that row (and cause a NullPointerException) is bm, which means Bitmap bm = view.getDrawingCache(); didn't work as intended. Can you post the stack trace?

0

精彩评论

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