Android Question Again: canvas - bitmap - imageview handling

Pflichtfeld

Active Member
Licensed User
First I want to apologize about my stupidness: I try to understand, but I do not. I hope, somebody can remove my blocks.

This is an very long :confused: instance, I am sorry:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Private pnl As Panel
    Private ImgV As ImageView
    Dim xui As XUI
    pnl.Initialize("")
    pnl.Color=Colors.Gray
    Activity.AddView(pnl,0,0,Activity.Width,Activity.Height)
    ImgV.Initialize("")
    ImgV.Color=Colors.White
    pnl.AddView(ImgV,10dip,10dip,300dip,300dip)
    'Return   
    'without commening RETURN, everything is fine. I see the gray activity and the white imageview
    
    'commenting above Return:
    Dim xview As B4XView = xui.CreatePanel("")
    xview.Color=Colors.Yellow    'seems to be shifted immediately to xview, although color it is set to 0 by canv.initialize below
    xview.SetLayoutAnimated(0, 0, 0, ImgV.Width*0.7, ImgV.Height*0.7)
    ImgV.Gravity=Gravity.CENTER
    ImgV.Bitmap=xview.Snapshot
    'Return
    'only the yellow xview on grey activity is shown. No white border from imgV
    'FIRST WHY?
    
    'commenting above Return:
    Dim gpx =createPath(xview) As B4XPath
    Dim canv As B4XCanvas
    canv.Initialize(xview)    'puts xview.color to 0 but does not remove yellow: SECOND WHY
    
    'if I use ImgV.Bitmap=xview.Snapshot below, that happens:THIRD WHY
    'xview.Color=Colors.Yellow    'uncomment: only yellow xview is seen on grey activity: No line, no path
    xview.Color=Colors.Transparent 'uncomment: nor xview nor imgV is seen, only gray activity
    'if above xview.color=Colors.yellow is commented, the background of xview stayes yellow: FOURTH WHY
    canv.DrawPath(gpx,Colors.Red,True,0)
    canv.DrawLine(0,0,200dip,200dip,Colors.Blue,2)
    canv.Invalidate
    ImgV.Bitmap=canv.CreateBitmap
    'ImgV.Bitmap=xview.Snapshot    'This way seems worse, CORRECT?
    
End Sub
createPath is short, just for testing:
B4X:
Private Sub createPath(xv As B4XView) As B4XPath
    Dim gpx As B4XPath
    Dim xx =xv.Width/2 As Int
    gpx.Initialize(xx,0)
    gpx.LineTo(2*xx,xx)
    gpx.LineTo(xx,2*xx)
    gpx.LineTo(0,xx)
    gpx.LineTo(xx,0)
    Return gpx
End Sub

I would like to understand these WHYs. Any help is appreciated! Thank you for your patience!
 

Pflichtfeld

Active Member
Licensed User
1. Upload a small project.
2. Post a single question.
Thank you Erel, I attach the test-project.
Sorry for serveral questions they are linked to make this issue clear for me and concern the same topic.
(Btw: I like your refreshing short answers ;))
 

Attachments

  • canvasBmp.zip
    8.8 KB · Views: 277
Upvote 0
Top