0

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

}
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

Samuel
  • 4,337
  • 3
  • 29
  • 35

1 Answers1

0

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?

Martin Algesten
  • 13,052
  • 4
  • 54
  • 77
  • two things, yeah, but how do I post the stack trace? and but when I put it into an imageview it works and shows the view picture.. – Samuel Nov 28 '10 at 08:19
  • Could this be the problem? http://stackoverflow.com/questions/2817166/android-2-1-views-getdrawingcache-method-always-returns-null – Martin Algesten Nov 28 '10 at 08:22
  • I assume it refers to http://developer.android.com/reference/android/view/View.html#onLayout(boolean,%20int,%20int,%20int,%20int) – Martin Algesten Nov 28 '10 at 08:31