Android Question Canvas - Pinch & Zoom and adding images

Pravin Shah

Member
Licensed User
Hi All,

I am using a Canvas object to draw chart on it. The chart is drawn using rectangle and lines. The chart is large in size and can't be fit in one screen so I would like to give a facility to user to zoom in / out of the chart. I understood that pinch and zoom can be used to provide this option. I have attached the image of the chart with the thread for reference.

So I have some questions -

1. How can I add the Pinch & Zoom functionality to this canvas so that app users can zoom in and out of the chart.

2. I also want to add images to the chart rectangles so that it occupies the rectangle (refer to attached chart), I am not sure how to do that. Also when the user zoom in or zoom out, these images should also become small or big proportionately.

3. Also I would like to capture the click event of these images and run some code.

Appreciate you help. thanks in advance.
 

Attachments

Pravin Shah

Member
Licensed User
I got following code for attaching images to the rect on canvas so this will be certainly useful. Now waiting for how to add zoom functionality

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
 
Top