I am making a drawing app in android.
Here I am saving the drawing on canvas as png image. I am using Bitmap array to save the drawing from canvas.
if(view.getId()==R.id.save_btn){
//save drawing
AlertDialog.Builder saveDialog = new AlertDialog.Builder(this);
saveDialog.setTitle("Save drawing");
saveDialog.setMessage("Save drawing to device Gallery?");
saveDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
int k=0;
//save drawing
while(bits[k]!=null) {
Bitmap m = null;
m = bits[k];
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
File file = new File(path + File.separator + "Pictures" + File.separator + k + "_image.png");
FileOutputStream ostream;
try {
file.createNewFile();
ostream = new FileOutputStream(file);
m.compress(Bitmap.CompressFormat.PNG, 100, ostream);
ostream.flush();
ostream.close();
Toast.makeText(getApplicationContext(), "image saved :" + path, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_SHORT).show();
}
k=k+1;
}
i=0;
bits=null;
}
}
}
Here I am saving the drawingCache of the view in to array of bitmap. Here even if my canvas is empty still an blank image is saved.
I dont want that. I want to save only if there is any drawing on the canvas.
So is there any way to do this??
Or is there any way to check whether there is any drawing on canvas??