Bonjour,
je souhaiterai exporter le contenu d’un Canvas sous forme de fichier JPEG ou PNG. Le nom du Canvas est Affichage. J’ai parcouru le forum et essay diverses solutions proposes A chaque fois, f.exists =false
Ceci semble normal d’aprs le Langage de Rfrence : “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.”
// ----------------------------------------//
// sauvegarde des courbes au format png //
// ----------------------------------------//
Dim jpegType As New FileType
jpegType.Name = “image/jpeg”
jpegType.MacType = “JPEG”
jpegType.MacCreator = “prvw”
jpegType.Extensions = “jpg;jpeg”
Dim pngType As New FileType
pngType.Name = “image/png”
pngType.MacType = "PNG "
pngType.MacCreator = “ogle”
pngType.Extensions = “png”
Dim f As FolderItem
dim g as graphics
//using the addition and conversion operators…
f = GetSaveFolderItem( jpegType + pngType,"" ) // une solution plus simple f = GetSaveFolderItem(“image/png”,"") et suppression de tout le bloc de dclaration
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
le seul exemple qui “fonctionne” est le suivant :
// ----------------------------------------//
// sauvegarde des courbes au format png //
// ----------------------------------------//
Dim f As FolderItem
dim g as graphics
dim pagesetup as new PrinterSetup
g = openPrinterDialog(pageSetup,Fenetre) // Fenetre est le nom de la fentre contenant le Canvas
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
J’obtiens un menu popup qui me permet d’enregistrer au format PDF, et de l, je peux convertir le PDF en n’importe quoi. Convivial n’est-il pas ?
Auriez-vous une solution ?
Merci