Android Question How to Draw 2 pictures in one panel

Mscal

Member
Licensed User
hi,
I use a drawer as canvas,a layout1 as panel,bitmap1 as bitmap,rect1 as rect

the main code is

rect1.Initialize(0,0,100,100)
drawer.DrawBitmap(bitmap1,Null,rect1)

rect1.Initialize(0,100,100,200)
drawer.DrawBitmap(bitmap1,Null,rect1)

when running it,i can only see the second image,please help me how can i draw 2 pictures in one panel
 

sorex

Expert
Licensed User
Longtime User
did you invalidate your drawer?

in some cases it won't show all changes unless you do that.

also re-dim a new rect1 for the second drawing might help
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
B4X:
       Dim drawer As Canvas
    Dim panel1 As Panel
    Dim bitmap1 As Bitmap
    Dim bitmap2 As Bitmap
    Dim rect1 As Rect
    Dim rect2 As Rect


B4X:
    bitmap1.Initialize(File.DirAssets,"pic1.jpg")
    bitmap2.Initialize(File.DirAssets,"pic2.jpg")
   
    drawer.Initialize(panel1)
  
  
    rect1.Initialize(0,0,panel1.Width/2,panel1.Height/2)
    drawer.DrawBitmap(bitmap1,Null,rect1)
  


    rect2.Initialize(20dip,10dip,100dip,100dip)
    drawer.DrawBitmap(bitmap2,Null,rect2)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Be aware of the Height/Width ratios of the bitmap and the destination rectangle.
If they are different the image will be distorted.
The Invalidate method refers to the Panel not the Canvas.
Panel1.Invalidate and not drawer.Invalidate.
 
Upvote 0
Top