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 atbm.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?
精彩评论