How to draw on Bitmap in android?

前端 未结 2 972
别那么骄傲
别那么骄傲 2020-12-11 15:34

I\'m trying to figure out how to draw on a bitmap in android, and keep a copy of these changed bitmaps for an undo function.

Bitmap b = ...
Paint p = new Pai         


        
相关标签:
2条回答
  • 2020-12-11 16:10

    Use new Canvas(Bitmap bitmap) to provide a Canvas with a Bitmap which will contain the result of your drawing operations.

    The original Bitmap that you draw on your Canvas with drawBitmap will never be modified.

    After each operation done by the user you might:

    • keep in memory a list of the operations done
    • save intermediate results to external storage with Bitmap.compress

    Another approach could be to use a LayerDrawable to stack successive drawing operations on top of each other. You can imagine allowing the user to disable each individual operation done.

    0 讨论(0)
  • 2020-12-11 16:14

    You can see complete guide how to draw text here:

    https://www.skoumal.net/en/android-how-draw-text-bitmap/

    Long story short:

    Copy your bitmap to make it mutable and create Canvas based on it.

    0 讨论(0)
提交回复
热议问题