I have a project that works by reading and showing graphics on the screen from ordinary windows.
Everything was fine until I bought a 4K monitor. Everything is out of position, and I can't solve this problem.
I attached a project trying to replicate my scenario.
Download the project here: https://1drv.ms/f/s!ArdqlgJhFnmYkiHuImTcA5_GVX89
Result in my good old 21 inch display:
4K display result:
Entire project:
Everything was fine until I bought a 4K monitor. Everything is out of position, and I can't solve this problem.
I attached a project trying to replicate my scenario.
Download the project here: https://1drv.ms/f/s!ArdqlgJhFnmYkiHuImTcA5_GVX89
Result in my good old 21 inch display:
4K display result:
Entire project:
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#AdditionalJar: jna-5.2.0
#AdditionalJar: jna-platform-5.2.0
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim OriginX, OriginY As Int
Dim SecondForm As Form
Dim img As ImageView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
' I read graphical elements from ordinary Windows forms wich i get by window name
' Mainform will play this part. See Scanwindow sub
MainForm.RootPane.LoadLayout("main")
MainForm.Title = "Window that I need to scan some graphical elements"
MainForm.Show
MainForm.AlwaysOnTop = True
ScanWindow ' as if mainform does not belong to the project
img.Initialize("")
SecondForm.Initialize("", 300,300)
SecondForm.RootPane.AddNode(img,0,0,SecondForm.Width, SecondForm.Height)
SecondForm.WindowLeft = OriginX + 300
SecondForm.WindowTop = OriginY + 300
SecondForm.Title = "Second"
SecondForm.BackColor = fx.Colors.Blue
SecondForm.AlwaysOnTop = True
End Sub
Sub Capture(x As Int, y As Int, width As Int, height As Int) As B4XBitmap
Dim c3po As AWTRobot
c3po.ScreenCurrentRectangleSetAsArbitrary(x, y, width, height)
Return BytesToImage(c3po.ScreenCaptureAsByteArray)
End Sub
Public Sub BytesToImage(bytes() As Byte) As B4XBitmap
Dim In As InputStream
In.InitializeFromBytesArray(bytes, 0, bytes.Length)
Dim bmpret As Image
bmpret.Initialize2(In)
Return bmpret
End Sub
Sub ScanWindow
Dim wu As JavaObject
wu.InitializeStatic("com.sun.jna.platform.WindowUtils")
' I need a list cause I scan several windows
Dim Ls As List = wu.RunMethod("getAllWindows",Array(True))
Dim tit As String
For Each JO As JavaObject In Ls
tit = JO.RunMethod("getTitle",Null)
If tit = "Window that I need to scan some graphical elements" Then
Dim awtrect As JavaObject = JO.RunMethod("getLocAndSize", Null)
OriginX = awtrect.GetField("x")
OriginY = awtrect.GetField("y")
Log("Form found")
Return
End If
Next
End Sub
Sub MainForm_CloseRequest (EventData As Event)
SecondForm.Close
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Button1_Click
Dim bmp As B4XBitmap
bmp = Capture(OriginX + 100, OriginY + 100, 300, 300)
img.SetImage(bmp)
SecondForm.Show
End Sub
Last edited: