Issue
I have drawn something on canvas and i want to save this drawing as jpeg image in my storage . Following method i used for that and it saving image sign.jpg in my directory but its saving blank black image nothing drawn on it its size 14.49kb .
Here is method for that
public Bitmap savebit(){
Bitmap saveBitmap = Bitmap.createBitmap(this.getWidth(), this.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(saveBitmap);
canvas.setBitmap(saveBitmap);
this.draw(canvas);
File file = new File(Environment.getExternalStorageDirectory() + "/sign.jpg");
try {
saveBitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(file));
} catch (Exception e) {
e.printStackTrace();
}
return saveBitmap;
}
Solution
Just pass your inflated view to the below function
Bitmap bmp = viewToBitmap(abc);
Bitmap bmp = viewToBitmap(frameLayout);
Bitmap bmp = viewToBitmap(LinearLayout);
Bitmap bmp = viewToBitmap(AnyView);
public Bitmap viewToBitmap(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
Answered By - Sohail Zahid
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.