Android Question Drawing on bitmap

John Decowski

Member
Licensed User
Longtime User
I have a bitmap on a file that I want to be able to draw it and an arrow onto a canvas to point to objects in the picture. I can't seem to figure out how to get a mutable image loaded from a saved file so I can draw a rect onto the canvas. Any ideas? I wanted to try and stay away from libraries simple because I am planning on porting this to B4i after.
 

eurojam

Well-Known Member
Licensed User
Longtime User
Here is a small example how to draw on an image:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim pn1 As Panel
    Dim bmp1 As Bitmap
    Dim bmp2 As Bitmap
    Dim cvs As Canvas
    Dim aRect As Rect
   
    bmp1.Initialize(File.DirAssets, "Bild1.png")
    bmp2.Initialize(File.DirAssets, "arrow.png")

    aRect.Initialize(0,0,100dip,100dip)
       
    pn1.Initialize("pn1")
    pn1.SetBackgroundImage(bmp1)
    Activity.AddView(pn1,0,0,100%x,100%y)
    cvs.Initialize(pn1)
    cvs.DrawCircle(100dip,100dip,100dip,Colors.Blue,True,2dip)
    cvs.DrawBitmapRotated(bmp2, Null, aRect, 30)
   
End Sub

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…