How to add different images on a Canvas

Vabzboy

Member
Licensed User
Longtime User
I have totally different images with distinctive names in the Files Folder.

I would like to add these images on one Canvas instead of having a different Canvas for each Image.

Is this possible and if it is How would i do it?

Thank you
 

klaus

Expert
Licensed User
Longtime User
Attached you have an example.
B4X:
Sub Globals
    Dim cvsActivity As Canvas
End Sub

Sub Activity_Create(FirstTime As Boolean)
    cvsActivity.Initialize(Activity)
End Sub

Sub Activity_Resume
    Dim i As Int
    Dim r As Rect
    Dim imgW, imgH, x, y As Int
    
    imgW = 50%x
    imgH = imgW / 3 * 2        ' image ratio W/H = 3/2
    For i = 0 To 3
        x = (i Mod 2) * imgW
        y = Floor(i / 2) * imgH
        r.Initialize(x, y, x + imgW, y + imgH)
        cvsActivity.DrawBitmap(LoadBitmap(File.DirAssets, "image" & i & ".jpg"), Null, r)
    Next
End Sub
Best regards.
 

Attachments

  • ImagesSameCanvas.zip
    185.8 KB · Views: 686
Upvote 0
Top