Android Question Panel drawing assistance needed

Nimbus4

Member
Licensed User
Longtime User
I can't seem to get this to work. I'm loading an image into PreviewPanel2, then overlapping that with DrawPanel. DrawPanel_Touch works because I can see the x coord being logged, but nothing is drawn. This code is edited, but I think you get the jist. The actual code is 2000+ lines.

Sub CameraModule
Activity.RemoveAllViews
Activity.LoadLayout("CameraScreen")
PreviewPanel2.Visible=False
DrawPanel.Visible=False
PreviewPanel.SetLayout(0dip, 0dip, Activity.Width,Activity.Height)
End Sub
Sub PicturePreview
Dim img As Bitmap
PreviewPanel2.SetLayout(0dip,0dip,Activity.Width,Activity.Height/2)
DrawPanel.SetLayout(0dip,0dip,Activity.Width,Activity.Height/2)
DrawPanel.Visible=True
MyImage.Initialize(PreviewPanel2)
DrawImage.Initialize(DrawPanel)
img.Initialize(File.DirInternal,PictureFileName)
PreviewPanel2.SetBackgroundImage(img)
Dest.Initialize(0dip, 0dip, PreviewPanel2.Width,PreviewPanel2.Height)
DrawImage.DrawRect(Dest,Colors.Transparent,True,1)
MyImage.DrawBitmap(img,Null,Dest)
PreviewPanel2.Invalidate
SizeImage
End Sub
Sub SizeImage
File.Delete(File.DirRootExternal, "TempImage.png")
Dim Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal, "TempImage.png", False)
MyImage.Bitmap.WriteToStream(Out, 100, "PNG")
Out.Close
img.Initialize(File.DirRootExternal,"TempImage.png")
PreviewPanel2.SetBackgroundImage(img)


Dim sizew As Double = img.Width
Dim sizeh As Double = img.Height
Dim ratio As Double = sizew / sizeh
Dim pw, ph As Int
If 100%y * ratio > 100%x Then
pw = 100%x
ph = pw / ratio
Else
ph = 100%y
pw = ph * ratio
End If
PreviewPanel2.SetLayout(50%x - pw / 2, 50%y - ph / 2, pw, ph)
DrawPanel.SetLayout(50%x - pw / 2, 50%y - ph / 2, pw, ph)
DrawPanel.BringToFront
End Sub
Sub DrawPanel_Touch(Action As Int, tx As Float, ty As Float)
If Main.kvs.ContainsKey("Drawing") = True Then
Try
DrawImage.DrawPoint(tx,ty,Colors.Red)
Log(tx)

Catch
Log(LastException)
End Try
End If
End Sub
 

ronell

Well-Known Member
Licensed User
Longtime User
before anything else.. please use code tags so it is easier for us to read the codes

 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
this paint into panel
B4X:
Sub Panel1_Touch (Action As Int, X As Float, Y As Float)

    Dim Canvas1 As Canvas
    Canvas1.Initialize(Panel1)
   
    'Canvas1.DrawPoint(X,Y,Colors.Red)
   
    Canvas1.DrawCircle(X,Y,3dip,Colors.Red,True,1dip)

     Panel1.Invalidate
               
End Sub
 
Upvote 0

Nimbus4

Member
Licensed User
Longtime User

OMG my brain must be fried. That worked. Thank you.
Everything wasn't working because I forgot DIP (I'm a dip)
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…