How to use specific width and height for bitmap on saving framelayout to image?
Asked
Active
Viewed 157 times
0

Vadim Kotov
- 8,084
- 8
- 48
- 62

Mahmoud Afarideh
- 306
- 4
- 20
-
What do you mean by "saving framelayout to image"? – FabioR Oct 29 '16 at 00:54
-
@FabioR converting framelayout to image with specific width and height – Mahmoud Afarideh Dec 02 '16 at 06:15
-
I don't understand what do you mean by "converting". You have a FrameLayout with an image as a background and you want to use pass the image to an ImageView, in example? – FabioR Dec 03 '16 at 17:54
-
@FabioR I have an framelayout and I add some text on it then convert it to bitmap. Don't you know about converting framelayout to bitmap and save it as an image? – Mahmoud Afarideh Dec 03 '16 at 17:57
-
This answer may help you http://stackoverflow.com/questions/21725916/convert-frame-layout-into-image-and-save-it – FabioR Dec 03 '16 at 18:00
1 Answers
1
Check following code
public Bitmap convertFrameToBitmap(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
ry {
FileOutputStream output = new FileOutputStream(getActivity().getFilesDir() + File.separator+ image.png");
bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
output.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

Jaykishan Sewak
- 822
- 6
- 13