Hello All,
I am saving a snapshot of my form to a PNG file. The form is 1100 x 800 pixels and I have the following in my code:
B4X:
#Region Project Attributes
#MainFormWidth: 1100
#MainFormHeight: 800
#End Region
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
MainForm.WindowWidth = 1100
MainForm.WindowHeight = 800
MainForm.Resizable=False
MainForm.Show
.
.
.
Then to take a a snapshot every minute, I use a timer with the following code:
B4X:
Sub Timer3_tick
Dim out As OutputStream = File.OpenOutput(File.DirApp, "temps.png", False)
MainForm.RootPane.SetSize(1100,800)
MainForm.RootPane.Snapshot.WriteToStream(out)
out.Close
End Sub
The code works fine and the PNG file is created as expected. However the size of the PNG file is always 2000 x 1131 pixels when I expected it to be the size of the mainform which is 1100 x 800.
Is there any way to get it to create the PNG of the same size as the mainform?
Any pointers on this issue would be greatly appreciated as I have now tried almost everything to change the PNG size from 2000 x 1131 but nothing works.
Sub Timer3_tick
Dim out As OutputStream = File.OpenOutput(File.DirApp, "temps.png", False)
Dim bmp As B4XBitmap = MainForm.RootPane.Snapshot
bmp.Resize(1100, 800, False).WriteToStream(out,100,"PNG")
out.Close
End Sub
Public Sub SnapShot (v As B4XView)
Dim out As OutputStream = File.OpenOutput(File.DirApp, "temps.png", False)
Dim bmp As B4XBitmap = v.Snapshot
bmp.Resize(1100, 800, False).WriteToStream(out,100,"PNG")
out.Close
End Sub
Thanks oparra! That did work.
However I did find out what the problem was. .... it was not in my code.
I had a text box placed in Designer that was out of the bounds of the 1100 x 800 form. I did not notice that I had placed it there. So I presume that because of this, the form size I specified was overridden with a new size to encompass the text box. Once I removed the textbox, the PNG was created in the expected size.
Running your code did resize the PNG but it also included the runaway textbox and that's how I found it.
Tx again!