Android Question Drawing to and Saving a ScaleImageView

bocker77

Active Member
Licensed User
Longtime User
What I am wanting to do is place bitmaps on various areas of the scaleimageview. I can place a bitmap but it gets removed when I place another one on it. If I can get this solved then the next question is how would I save it to a file.

Here is how I am placing the bitmap. I am guessing from the comment that the OnDraw event automatically redraws. I have tried to do the draw in the click using my own canvas but no luck.
B4X:
Sub ScaleImageView1_Click 'The user has tapped on the view. Use ClickImage or ClickView for the coordinates.
    Dim siv As ScaleImageView = Sender
    imagex =  siv.ClickImageX
    imagey =  siv.ClickImageY
'    siv.Invalidate ' draw the new position
End Sub

Sub ScaleImageView1_OnDraw(viewcanvas As Canvas) 'The view is being redrawn. Use viewcanvas to draw on it.
    Dim siv As ScaleImageView = Sender
    Dim viewxy() As Float = siv.SourceXYtoViewXY(imagex, imagey)
    Dim r As Rect
    r.Initialize(viewxy(0), viewxy(1), viewxy(0) + 30dip, viewxy(1) + 30dip)
    viewcanvas.DrawBitmap(bmpGermany, Null, r)
    siv.Invalidate2(r)
End Sub
 

bocker77

Active Member
Licensed User
Longtime User
I believe I know how to save the image with this code. But still having problems with placing numerous bitmaps on the ScaleViewImage.

B4X:
Dim b as BitMap
b = ScaleViewImage1.Image
b.WriteToStream(...)
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I can place a bitmap but it gets removed when I place another one on it.
It will, you will need to keep a list of previous bitmaps and redraw them all in the required Z-order in the OnDraw event. Your save image code should work.
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
Do you mean like use a map with the coordinates bitmap and on every ondraw rifle through the map placing the old ones back on?

Also thanks for the assist.
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
But I need to keep track of which bitmap goes where. And also a map will do a replacemet where a list will not. I guess I can come up with something to achieve the requirement of the order. At least now I know how the OnDraw routine works. I think!

I love this library as to how smoothly the image scrolls. It is quite large. And just as a side note my current code using your library is doing what I needed it to do. This placing bitmaps on the image is something that would be nice to have.
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
So William, b4XOrderedMap will honor the Z-order as Andrew said is required for this to work? In other words would a Put that replaces an item mess up that Z-order that is required?
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
The order of the keys as they are Put will be retained.
The values could be the additional info you need (position for example or the actual bitmap).

The Map structure will do that in B4J and B4A but not in B4i.
The B4XOrderedMap will do it for all three platforms.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Demo of retained order:
B4X:
    Dim om As B4XOrderedMap
    om.Initialize
    om.Put("aaaa", 1)
    om.Put("bbbb", 2)
    om.Put("cccc", 3)
    om.Put("dddd", 4)
    
    For Each kw As String In om.Keys
        Log(kw & TAB & om.Get(kw))
    Next
    Log(TAB)
        
    om.Put("bbbb", 999)

    For Each kw As String In om.Keys
        Log(kw & TAB & om.Get(kw))
    Next
    
'Log:   
'    aaaa    1
'    bbbb    2
'    cccc    3
'    dddd    4
'   
'    aaaa    1
'    bbbb    999
'    cccc    3
'    dddd    4
 
Upvote 0
Top