I've made an application with an ImageView that displays a Bitmap drawn by the user and everything goes well, but now I want to give the possibility to the user to save the image from the ImageView to a jpeg file when I click on a button. How can I do this?
Here is my code:
ImageView imageview;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageview=(ImageView)findViewById(R.id.imageviewcomponent);
imageview.setDrawingCacheEnabled(true);
}
//This method sets the Bitmap into the ImageView from the ActivityResult of the Drawing Activity
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == get_code && resultCode == RESULT_OK)
{
iv.setImageBitmap((Bitmap) data.getParcelableExtra("Painting"));
}
}
//This is the onClick method of the button for saving the image
public void SaveAsImage(View btsave) throws FileNotFoundException {
Bitmap b=Bitmap.createBitmap(imageview.getWidth(), imageview.getHeight(), Bitmap.Config.ARGB_8888);
OutputStream fOut = null;
new File("/sdcard/signatures").mkdir();
fOut = new FileOutputStream("/sdcard/myPaintings/image.jpg");
b.compress(CompressFormat.JPEG, 95, fOut);
}
The code for creating the folder and save the image is working, because I can find an image.jpg file in the myPainting folder, but the image's content is completely black, without the image drawn by the user. How can I get the content of the ImageView? (rather in Bitmap format then other things)