Hello
I would like to export the content of a Canvas as a jpg, png file for example. I went through some topics in this forum and I have tested some of the proposed solutions (see below) using f.GetSaveFolderItem. It fails : at any time, the file that I created does not exist (f.Exists = false)
It seems to be normal according to the Language reference : “The GetSaveFolderItem function does not create the file. It simply returns a FolderItem that represents the potential file. To create the actual file, you will need to call or Create shared method for TextOutputStream or the Create shared method of the BinaryStream.”
For your understanding : Affichage is the Canvas - Fenetre is the Window containing Affichage
// ----------------------------------------//
// sauvegarde des courbes au format png //
// ----------------------------------------//
Dim f As FolderItem
dim g as graphics
//using the addition and conversion operators…
f = GetSaveFolderItem( “image/png”,"" )
If f.Exists then
//file saved
dim imp as new Picture( Affichage.Width, Affichage.Height, 32)
Affichage.DrawInto imp.Graphics, 0, 0
dim gheight as Integer = g.Width/imp.Width*imp.Height
imp.Save(f,imp.SaveAsPng)
Else
MsgBox(“le fichier n’existe pas”)
End if
The only one example which is “working” is the following
// ----------------------------------------//
// sauvegarde des courbes au format png //
// ----------------------------------------//
Dim f As FolderItem
dim g as graphics
dim pagesetup as new PrinterSetup
g = openPrinterDialog(pageSetup,Fenetre) // Fenetre is the name of the window containing the Canvas “Affichage”
if g<>nil then
dim imp as new Picture( Affichage.Width, Affichage.Height, 32)
Affichage.DrawInto imp.Graphics, 0, 0
dim gheight as Integer = g.Width/imp.Width*imp.Height
g.DrawPicture imp, 0, 0, g.Width, gheight, 0, 0, imp.Width, imp.Height
end if
I get the relevant popup menu for printing, and I can choose “Print as Pdf” and open the PDF in a PDF viewer. From ther, I can export in whatever format. User friendly, isn’ it ?
Do you get a solution ?
Thanks
P.S : I posted this topic 3 hours ago in the French forum. Sorry for any English mistakes.