简体   繁体   中英

Convert view into bitmap with modification

Requirement : User should be able to share the layout(which has image and text) as image.

Solution which i tried:

   Bitmap b = Bitmap.createBitmap(myView.getWidth(), myView.getHeight(), Bitmap.Config.ARGB_8888);
   Canvas c = new Canvas(b);
   myView.draw(c);

This is working as expected. But I have few issues.

Issues : I have few buttons and text which i don't want to convert as image. Also,I want to add my App logo as a watermark on the Bitmap image.

My solution for the above issue :

  • Before converting to Bitmap Image, Change visibility state of Button and Logo Image
  • Create one more layout behind the actual layout in a sharable image format. Use this layout to get Bitmap Image (not cool efficient, But easy way)

My question: The above solutions are valid? Or Is there any other method to do in an efficient way?

PS: I am not looking for code. :)

Issue 1: yes, you have to change visibility of those views you don't want them to be converted into image(the easiest way).

Issue 2: for adding a watermark, you can just draw it on canvas(you can use canvas.drawBitmap to do it) instead of putting it in the layout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM