Android Question How to draw on a bitmap, save and can undo?

Sapta

Member
Licensed User
Longtime User
How to draw on a bitmap as shown below (can draw like point A to B)?
And can be saved and undo.

Does anyone have the full code?
2eckyz7.png


I found some code, but could not combine
B4X:
    'Make a new copy of the existing bitmap and save it
    Dim bt As Bitmap
    bt.InitializeMutable(b.Width,b.Height)
    Dim cv As Canvas
    cv.Initialize2(bt)
    'Dim rect1 As Rect
    'rect1.Initialize(0,0,b.Width,b.Height)
    'cv.DrawBitmap(b,Null,rect1)

    'c.DrawCircle(X,Y,5dip,Colors.Red,True,1dip)
    'ImageView1.Invalidate
    undo.Add(bt)

    Select action
        Case Activity.ACTION_DOWN
            x1 = X
            y1 = Y
            c.DrawCircle(x1, y1, Radius, LineColor, True, 1dip)
            rect1.Left = x1 - Radius
            rect1.Top = y1 - Radius
            rect1.Right = rect1.Left + LineWidth
            rect1.Bottom = rect1.Top + LineWidth
            ImageView1.Invalidate2(rect1)
        Case Activity.ACTION_MOVE
            x2 = X
            y2 = Y
            c.DrawCircle(x1, y1, Radius, LineColor, True, 1)
            c.DrawLine(x1, y1, x2, y2, LineColor, LineWidth)
            rect1.Left = Min(x1, x2) - Radius
            rect1.Top = Min(y1, y2) - Radius
            rect1.Right = Max(x1, x2) + LineWidth
            rect1.Bottom = Max(y1, y2) + LineWidth
            ImageView1.Invalidate2(rect1)
            x1 = x2
            y1 = y2
    End Select
 

Sapta

Member
Licensed User
Longtime User
Do you want to draw over the map or over a regular bitmap?

The point I was able to save the image / bitmap result of surveyors at the site by using existing maps sketches to our survey results with FTP upload

Which allows such case the above? drawing on google map and then saved to a bitmap or over a regular bitmap?
 
Upvote 0

Sapta

Member
Licensed User
Longtime User
Thank Erel, I already get the snapshot map on this post. My question is, when the map File.DirRootExternal is already a bitmap, then I would like to sketch in the picture and saved (along with a sketch map) to 1 bitmap, and could undo the current drawing. Do you have the full code?
thank you
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
On a conceptual level, the simplest way to undo is to keep a list of the various states of the bitmap, and if/when the user clicks Undo, you show the previous version and so on.

If memory or storage is scarce, then you can be a bit smarter by storing the original image, and then storing the rectangular area that changed (which is often much smaller than the entire bitmap). Then, if/when the user clicks Undo, you restore just the rectangle itself. (This is what I do in my Quick Proto drawing app, and it lets me save about 30 Undo steps instead of about 3 for the first method described above.

If you need to get smarter than that, it's probably best to draw with superimposed vectors instead of bitmaps. But that's beyond my kung fu. :D
 
Upvote 0
Top