hi all .. i m using this code to take a snapshot of a form and then print it :
B4X:
Sub Button1_Action
Dim out As OutputStream = File.OpenOutput(File.DirApp, "image.png", False)
MainForm.RootPane.Snapshot.WriteToStream(out)
out.Close
Dim params As List
params.Initialize
'params.Add("printername=novapdf")
params.Add("file=template.html")
sh.Initialize("sh", "printhtml.exe", params)
sh.WorkingDirectory = File.DirApp
sh.Run(-1)
End Sub
is there a way to improve the resulted image quality ? it s toooo hazy
also is there a way to set the image size to fit A4 page size ??? should this be done on the form width/hight level ?? i.e before taking the snapshot ?
What if you set your MainForm.WindowWidth = 4000 and MainForm.WindowHeight = 4000? Do you get a 4000x4000 px image?
If not, you need to do 2 subs:
B4X:
Sub SnapShot
MainForm.WindowWidth = 4000
MainForm.WindowHeight = 4000
CallSubDelayed(Me, "SaveImage")
End sub
Sub SaveImage
Dim out AsOutputStream = File.OpenOutput(File.DirApp, "image.png", False)
MainForm.RootPane.Snapshot.WriteToStream(out)
out.Close
End Sub
That will leave some time for the MainForm to scale up before taking the snapshot
A4 is a document format, as a screen image that's going to depend on the image resolution, for example an A4 document resized to:
72 dpi (web) = 595 X 842 pixels.
300 dpi (print) = 2480 X 3508 pixels (This is "A4" as I know it, i.e. "210mm X 297mm@ 300 dpi")
600 dpi (print) = 4960 X 7016 pixels.Oct 12, 2005
Sub SnapShot
MainForm.WindowWidth = 1500
MainForm.WindowHeight = 2121
For Each n As Node In MainForm.RootPane.GetAllViewsRecursive
Try
n.Left=n.Left * 1.6
n.PrefWidth=n.PrefWidth * 1.6
n.top=n.top * 1.6
n.Prefheight=n.Prefheight * 1.6
' If n Is Label or n is Then
n.Style="-fx-font-size: 18; -fx-font-weight: bold"
' End If
Catch
End Try
Next
CallSubDelayed(Me, "SaveImage")
End Sub
that gave me much better results
i might have to rescale back to orginial sizes after the snapshot
Sub SnapShot
Dim jo As JavaObject = MainForm.RootPane
jo.runMethod("setScaleX", Array(2.0))
jo.runMethod("setScaleY", Array(2.0))
CallSubDelayed(Me, "SaveImage")
End Sub
This code will "zoom" nodes (including fonts)
or something like this:
B4X:
For Each n As Node In MainForm.RootPane.GetAllViewsRecursive
Dim jo As JavaObject = n
jo.runMethod("setScaleX", Array(1.6))
jo.runMethod("setScaleY", Array(1.6))
Next