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
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