ECHEC DE SAVEPICTURE D'UNE PICTUREBOX !

Résolu
tilp Messages postés 10 Date d'inscription mardi 12 octobre 2004 Statut Membre Dernière intervention 16 novembre 2008 - 9 janv. 2007 à 17:47
jmfmarques Messages postés 7666 Date d'inscription samedi 5 novembre 2005 Statut Membre Dernière intervention 22 août 2014 - 9 janv. 2007 à 22:32
Bonjour,

J'ai actuellement une Form (Form1) dans laquelle j'ai mis une grille avec des valeurs dedans, un bouton de command (Command1) et une PictureBox (Picture1).
J'aimerai pouvoir copier la grille et uniquement la grille dans ses dimensions exactes pour la transférer dans Picture1 et ensuite pouvoir sauver cette PictureBox en format Bmp dans mon ordinateur.
La copie avec l'api BitBlit se passe sans problème, ma grille est bien copiée dans la PictureBox mais il m'est impossible ensuite de sauver le contenu de la PictureBox dans mon ordinateur.
Pourquoi ? je ne sais pas. Ma propriété autoredraw à false ou true de la picture n'a aucune  incidence et j'obtiens à chaque fois un message d'erreur d'exécution 380 au moment du savepicture !

Est il possible de copier de cette manière une partie d'une form quelconque ou tout simplement un controle comme une grille dans une PictureBox (oui à priori j'y arrive) et ensuite de sauver cette PictureBox en format bmp (voir jpg) immédiatement après (au moment de l'échec la valeur Picture1.picture =0 ?

Merci pour votre aide précieuse !


-----------------------------------------------------------------
Voici le code utilisé
------------------------------------------------------------------

Déclaration générale

Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
-------------------------------------------------------------------

Private Sub Command1_Click()

Dim Desktop As Long
Desktop = GetDC(GetDesktopWindow)



'je determine le controle grille à copier
Dim Ctrl As Control
Set Ctrl =gridAcopier

'je donne les valeurs  en pixels de mon controle (left, top, width, height)
xx = Ctrl.Left / Screen.TwipsPerPixelX
yy = Ctrl.Top / Screen.TwipsPerPixelY
ww = Ctrl.Width / Screen.TwipsPerPixelX
hh = Ctrl.Height / Screen.TwipsPerPixelY



'je copie la grille dans Picture1 avec l'api BitBlt
BitBlt Picture1.hDC, 0, 0, ww, hh, Desktop, xx , yy, &HCC0020


'je resize la Picture1 pour qu'elle soit exactement au dimension de ma grille
Picture1.Width = Ctrl.Width
Picture1.Height = Ctrl.Height

'Je sauve ma Picture en format bmp avec la méthode savepicture
SavePicture Picture1.Picture, "c:\test" & ".bmp"

A ce niveau de code, echec : "Erreur d'éxécution 380": valeur de propriété incorrecte !

End Sub

-------------------------------------------------------------

MERCI POUR VOTRE AIDE A VENIR...

Philippe

6 réponses

jmfmarques Messages postés 7666 Date d'inscription samedi 5 novembre 2005 Statut Membre Dernière intervention 22 août 2014 27
9 janv. 2007 à 18:13
1) Lis celà (aide en ligne en anglais chez moi) :

Returns a handle to a persistent graphic; the handle is provided by the Microsoft Windows operating environment.


Syntax


object.Image


The object placeholder represents an object expression that evaluates to an object in the Applies To list.


Remarks


An object's AutoRedraw property determines whether the repainting of an object occurs with a persistent graphics or through Paint events. The Windows operating environment identifies an object's persistent graphic by assigning a handle to it; you can use the Image property to get this handle.


An Image value exists regardless of the setting for the AutoRedraw property. If AutoRedraw is True and nothing has been drawn, the image displays only the color set by the BackColor property and the picture.


You can assign the value of Image to the Picture property. The Image property also provides a value to pass to Windows API
calls.



The Image, DragIcon, and Picture properties are normally used when assigning values to other properties, when saving with the SavePicture statement, or when placing something on the Clipboard. You can't assign these to a temporary variable, other than the Picture data type.


The AutoRedraw property can cause Image, which is a handle to a bitmap, to change. When AutoRedraw is True, an object's hDC property becomes a handle to a device context that contains the bitmap returned by Image.

2) adapte en conséquence ta syntaxe, qui doit être, à ton choix, l'ine des deux suivantes :

-   SavePicture Picture1.Image, "c:\test" & ".bmp"

- Picture1.Picture = Picture1. Image
- SavePicture Picture1.Picture, "c:\test" & ".bmp"

Il vaut également mieux faire précéder ton BitBlt par un Picture1.autoredraw = true
3
cs_caramelmou Messages postés 56 Date d'inscription jeudi 25 décembre 2003 Statut Membre Dernière intervention 23 avril 2008 3
9 janv. 2007 à 18:08
essaie plutôt
SavePicture Picture1.Image, "c:\test" & ".bmp"

avec autoredraw de picture1 = True

;)

Dr.T
1
cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
9 janv. 2007 à 18:13
Salut
Sans l'essayer, à l'inspiration, moi je n'aurais mis que Picture1 dans l'instruction, histoire de donner le nom de l'objet.
Mais ça, ça se retrouve dans l'aide de l'instruction SavePicture ...
0
jmfmarques Messages postés 7666 Date d'inscription samedi 5 novembre 2005 Statut Membre Dernière intervention 22 août 2014 27
9 janv. 2007 à 18:14
Ah ! Croisés avec Caramelmou
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
tilp Messages postés 10 Date d'inscription mardi 12 octobre 2004 Statut Membre Dernière intervention 16 novembre 2008
9 janv. 2007 à 22:20
En effet avec les instructions suivantes :

Picture1.autoredraw = true
Picture1.Picture = Picture1.Image
SavePicture Picture1.Picture, "c:\test" & ".bmp"

Mon problème est résolu ! Je peux dorénavant dans n'importe quelle form sauver en picture n'importe quel controle ou partie du formulaire en fichier bmp que je convertirai ensuite en jpg. Merci encore à vous !
0
jmfmarques Messages postés 7666 Date d'inscription samedi 5 novembre 2005 Statut Membre Dernière intervention 22 août 2014 27
9 janv. 2007 à 22:32
Hé ! Tilp !

Valide également la réponse (c'est la même en plus bref ) de Caramelmou, s'il te plait ...
0
Rejoignez-nous