In this code I’m trying to:
- get a bitmap from an ImageView
- save it as “er.png”
- then load it and assign it to another ImageView
here’s my code… but it keeps firing the exception that it can’t write… any ideas what might be causing it? Maybe it needs some permissions?
////// GET FROM IV /////////////////////////////////////
ImageView iv = (ImageView)findViewById(R.id.ivDon);
Drawable draw = iv.getBackground();
Bitmap bm = ((BitmapDrawable)draw).getBitmap();
Bitmap bmHue = Hue(bm,180);
//////////////////////////// SAVE ///////////
Bitmap bbicon = bmHue;
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
OutputStream outStream = null;
File file = new File(extStorageDirectory, "er.PNG");
try {
outStream = new FileOutputStream(file);
bbicon.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
}
catch(Exception e)
{Toast.makeText(this, "error writing :/", 5000).show();} // <- this exception fires.
///////////////////////////// LOAD //////////////
java.io.FileInputStream in = null;
try {
in = openFileInput("er.PNG");
} catch (FileNotFoundException e)
{Toast.makeText(this, "error reading :/", 5000).show();}
////////////////////////////// ASSIGN ///////////////
ImageView iv1 = (ImageView)findViewById(R.id.iv01);
iv1.setImageBitmap(BitmapFactory.decodeStream(in));
Thanks!
Try adding:
to the manifest