> Oui, mais sa me dit pas comment faire pour recuperer l'image du
> tt ça.
hehe ! patience ! :O)
Je t'ai fais un petit exemple qui sauvegarde un Bitmap de 24bits sur le
disque.
Au démarrage du programme, un screenshot du systray est copié dans le
picture. Il ne te reste qu'à appuyer sur sur "Sauvegarder" pour créer
l'image.
'***
' Form 1
' 1 PictureBox
' 1 CommandButton
' 1 Timer
Option Explicit
' Constante désignant "BM" pour l'entête du fichier
Private Const BMP_MAGIC_COOKIE = &H4D42
' Information relative à l'entête du bitmap
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
blWidth As Long
blHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
' Information relative à l'entête du fichier
Private Type BITMAPFILEHEADER '14 bytes
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function PrintWindow _
Lib "user32" ( _
ByVal hWnd As Long, _
ByVal hdcBlt As Long, _
ByVal nFlags As Long) As Long
Private Declare Function CreateCompatibleDC _
Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Declare Function CreateCompatibleBitmap _
Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal nWidth As Long, _
ByVal nHeight 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 Declare Function GetDIBits _
Lib "gdi32" _
( _
ByVal hDC As Long, _
ByVal hBitmap As Long, _
ByVal nStartScan As Long, _
ByVal nNumScans As Long, _
ByRef lpBits As Any, _
ByRef lpBI As BITMAPINFOHEADER, _
ByVal wUsage As Long _
) As Long
Private Declare Function SelectObject _
Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal hObject As Long) As Long
Private Declare Function DeleteObject _
Lib "gdi32" ( _
ByVal hObject As Long) As Long
Private Declare Function DeleteDC _
Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Sub Form_Load()
Call Me.Move(Me.Left, Me.Top, 6525, 1725)
Call Picture1.Move(120, 120, 6135, 495)
Call Command1.Move(4800, 720, 1465, 375)
Timer1.Interval = 10
Command1.Enabled = False
Command1.Caption = "&Sauvegarder"
Me.ScaleMode = vbPixels
Me.Caption = "Démo de sauvegarde d'image"
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = False
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Command1.Enabled = True
Call PrintWindow(FindWindow("Shell_TrayWnd", vbNullString),
Picture1.hDC, 0)
End Sub
Private Sub Command1_Click()
Const FILE_NAME As String = "c:picture1.bmp"
Call SavePictureBoxToBMP(Picture1.hDC, 0, 0, Picture1.ScaleWidth,
Picture1.ScaleHeight, FILE_NAME)
Call Shell("mspaint """ & FILE_NAME & """", vbNormalFocus)
End Sub
Public Sub SavePictureBoxToBMP( _
ByRef hDCSrc As Long, _
ByRef lPosX As Long, _
ByRef lPosY As Long, _
ByRef lWidth As Long, _
ByRef lHeight As Long, _
ByRef sFileName As String)
Dim hDC As Long
Dim hDIB As Long
Dim hOldDIB As Long
Dim biHeader As BITMAPINFOHEADER
Dim lScanLine As Long
Dim byDIB() As Byte
' initialise notre DC
hDC = CreateCompatibleDC(hDCSrc)
hDIB = CreateCompatibleBitmap(hDCSrc, lWidth, lHeight)
hOldDIB = SelectObject(hDC, hDIB)
' copie le contenu du DCSrc dans notre DC
Call BitBlt(hDC, 0, 0, lWidth, lHeight, hDCSrc, lPosX, lPosY,
' obtient l'entete du bitmap
biHeader = CreateBIHeader(lWidth, lHeight, byDIB)
' obtient les octets du DIB
Call GetDIBits(hDC, hDIB, 0, lHeight, byDIB(0, 0), biHeader, 0)
' sauvegarde le fichier
Call SaveFileAs(sFileName, biHeader, CreateBFHeader(biHeader), byDIB)
' Libère les ressources
Call SelectObject(hDC, hOldDIB)
Call DeleteObject(hDIB)
Call DeleteDC(hDC)
End Sub
Private Function CreateBIHeader( _
ByRef lWidth As Long, _
ByRef lHeight As Long, _
ByRef byDIB() As Byte) As BITMAPINFOHEADER
Dim lScanLine As Long
' prépare notre entete de bitmap
With CreateBIHeader
.biSize = Len(CreateBIHeader)
.biBitCount = 24
.biPlanes = 1
.blHeight = lHeight
.blWidth = lWidth
lScanLine = (((.blWidth * .biBitCount) + &H1F) And Not &H1F) &H8
.biSizeImage = lScanLine * .blHeight
ReDim byDIB(lScanLine - 1, CreateBIHeader.blHeight - 1) As Byte
End With
End Function
Private Function CreateBFHeader(ByRef biHeader As BITMAPINFOHEADER) As
BITMAPFILEHEADER
' initialise l'entete du fichier
With CreateBFHeader
.bfType = BMP_MAGIC_COOKIE
.bfOffBits = Len(CreateBFHeader) + Len(biHeader)
.bfSize = .bfOffBits + biHeader.biSizeImage
End With
End Function
Private Function SaveFileAs( _
ByRef sFileName As String, _
ByRef biHeader As BITMAPINFOHEADER, _
ByRef bfHeader As BITMAPFILEHEADER, _
ByRef byDIB() As Byte) As Boolean
Dim hFile As Long
' supprime le fichier s'il existe déjà
If (FileExists(sFileName)) Then
Call Kill(sFileName)
End If
' sauvegarde l'image dans le fichier
hFile = FreeFile
Open sFileName For Binary As #hFile
Put #hFile, , bfHeader
Put #hFile, , biHeader
Put #hFile, , byDIB
Close #hFile
End Function
Private Function FileExists(ByRef sFileName As String) As Boolean
On Error Resume Next
FileExists = ((GetAttr(sFileName) And vbDirectory) = 0)
End Function
'***
--
Cordialement
Yanick
MVP pour Visual Basic
> Oui, mais sa me dit pas comment faire pour recuperer l'image du
> tt ça.
hehe ! patience ! :O)
Je t'ai fais un petit exemple qui sauvegarde un Bitmap de 24bits sur le
disque.
Au démarrage du programme, un screenshot du systray est copié dans le
picture. Il ne te reste qu'à appuyer sur sur "Sauvegarder" pour créer
l'image.
'***
' Form 1
' 1 PictureBox
' 1 CommandButton
' 1 Timer
Option Explicit
' Constante désignant "BM" pour l'entête du fichier
Private Const BMP_MAGIC_COOKIE = &H4D42
' Information relative à l'entête du bitmap
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
blWidth As Long
blHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
' Information relative à l'entête du fichier
Private Type BITMAPFILEHEADER '14 bytes
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function PrintWindow _
Lib "user32" ( _
ByVal hWnd As Long, _
ByVal hdcBlt As Long, _
ByVal nFlags As Long) As Long
Private Declare Function CreateCompatibleDC _
Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Declare Function CreateCompatibleBitmap _
Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal nWidth As Long, _
ByVal nHeight 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 Declare Function GetDIBits _
Lib "gdi32" _
( _
ByVal hDC As Long, _
ByVal hBitmap As Long, _
ByVal nStartScan As Long, _
ByVal nNumScans As Long, _
ByRef lpBits As Any, _
ByRef lpBI As BITMAPINFOHEADER, _
ByVal wUsage As Long _
) As Long
Private Declare Function SelectObject _
Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal hObject As Long) As Long
Private Declare Function DeleteObject _
Lib "gdi32" ( _
ByVal hObject As Long) As Long
Private Declare Function DeleteDC _
Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Sub Form_Load()
Call Me.Move(Me.Left, Me.Top, 6525, 1725)
Call Picture1.Move(120, 120, 6135, 495)
Call Command1.Move(4800, 720, 1465, 375)
Timer1.Interval = 10
Command1.Enabled = False
Command1.Caption = "&Sauvegarder"
Me.ScaleMode = vbPixels
Me.Caption = "Démo de sauvegarde d'image"
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = False
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Command1.Enabled = True
Call PrintWindow(FindWindow("Shell_TrayWnd", vbNullString),
Picture1.hDC, 0)
End Sub
Private Sub Command1_Click()
Const FILE_NAME As String = "c:picture1.bmp"
Call SavePictureBoxToBMP(Picture1.hDC, 0, 0, Picture1.ScaleWidth,
Picture1.ScaleHeight, FILE_NAME)
Call Shell("mspaint """ & FILE_NAME & """", vbNormalFocus)
End Sub
Public Sub SavePictureBoxToBMP( _
ByRef hDCSrc As Long, _
ByRef lPosX As Long, _
ByRef lPosY As Long, _
ByRef lWidth As Long, _
ByRef lHeight As Long, _
ByRef sFileName As String)
Dim hDC As Long
Dim hDIB As Long
Dim hOldDIB As Long
Dim biHeader As BITMAPINFOHEADER
Dim lScanLine As Long
Dim byDIB() As Byte
' initialise notre DC
hDC = CreateCompatibleDC(hDCSrc)
hDIB = CreateCompatibleBitmap(hDCSrc, lWidth, lHeight)
hOldDIB = SelectObject(hDC, hDIB)
' copie le contenu du DCSrc dans notre DC
Call BitBlt(hDC, 0, 0, lWidth, lHeight, hDCSrc, lPosX, lPosY,
' obtient l'entete du bitmap
biHeader = CreateBIHeader(lWidth, lHeight, byDIB)
' obtient les octets du DIB
Call GetDIBits(hDC, hDIB, 0, lHeight, byDIB(0, 0), biHeader, 0)
' sauvegarde le fichier
Call SaveFileAs(sFileName, biHeader, CreateBFHeader(biHeader), byDIB)
' Libère les ressources
Call SelectObject(hDC, hOldDIB)
Call DeleteObject(hDIB)
Call DeleteDC(hDC)
End Sub
Private Function CreateBIHeader( _
ByRef lWidth As Long, _
ByRef lHeight As Long, _
ByRef byDIB() As Byte) As BITMAPINFOHEADER
Dim lScanLine As Long
' prépare notre entete de bitmap
With CreateBIHeader
.biSize = Len(CreateBIHeader)
.biBitCount = 24
.biPlanes = 1
.blHeight = lHeight
.blWidth = lWidth
lScanLine = (((.blWidth * .biBitCount) + &H1F) And Not &H1F) &H8
.biSizeImage = lScanLine * .blHeight
ReDim byDIB(lScanLine - 1, CreateBIHeader.blHeight - 1) As Byte
End With
End Function
Private Function CreateBFHeader(ByRef biHeader As BITMAPINFOHEADER) As
BITMAPFILEHEADER
' initialise l'entete du fichier
With CreateBFHeader
.bfType = BMP_MAGIC_COOKIE
.bfOffBits = Len(CreateBFHeader) + Len(biHeader)
.bfSize = .bfOffBits + biHeader.biSizeImage
End With
End Function
Private Function SaveFileAs( _
ByRef sFileName As String, _
ByRef biHeader As BITMAPINFOHEADER, _
ByRef bfHeader As BITMAPFILEHEADER, _
ByRef byDIB() As Byte) As Boolean
Dim hFile As Long
' supprime le fichier s'il existe déjà
If (FileExists(sFileName)) Then
Call Kill(sFileName)
End If
' sauvegarde l'image dans le fichier
hFile = FreeFile
Open sFileName For Binary As #hFile
Put #hFile, , bfHeader
Put #hFile, , biHeader
Put #hFile, , byDIB
Close #hFile
End Function
Private Function FileExists(ByRef sFileName As String) As Boolean
On Error Resume Next
FileExists = ((GetAttr(sFileName) And vbDirectory) = 0)
End Function
'***
--
Cordialement
Yanick
MVP pour Visual Basic
> Oui, mais sa me dit pas comment faire pour recuperer l'image du
> tt ça.
hehe ! patience ! :O)
Je t'ai fais un petit exemple qui sauvegarde un Bitmap de 24bits sur le
disque.
Au démarrage du programme, un screenshot du systray est copié dans le
picture. Il ne te reste qu'à appuyer sur sur "Sauvegarder" pour créer
l'image.
'***
' Form 1
' 1 PictureBox
' 1 CommandButton
' 1 Timer
Option Explicit
' Constante désignant "BM" pour l'entête du fichier
Private Const BMP_MAGIC_COOKIE = &H4D42
' Information relative à l'entête du bitmap
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
blWidth As Long
blHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
' Information relative à l'entête du fichier
Private Type BITMAPFILEHEADER '14 bytes
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function PrintWindow _
Lib "user32" ( _
ByVal hWnd As Long, _
ByVal hdcBlt As Long, _
ByVal nFlags As Long) As Long
Private Declare Function CreateCompatibleDC _
Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Declare Function CreateCompatibleBitmap _
Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal nWidth As Long, _
ByVal nHeight 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 Declare Function GetDIBits _
Lib "gdi32" _
( _
ByVal hDC As Long, _
ByVal hBitmap As Long, _
ByVal nStartScan As Long, _
ByVal nNumScans As Long, _
ByRef lpBits As Any, _
ByRef lpBI As BITMAPINFOHEADER, _
ByVal wUsage As Long _
) As Long
Private Declare Function SelectObject _
Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal hObject As Long) As Long
Private Declare Function DeleteObject _
Lib "gdi32" ( _
ByVal hObject As Long) As Long
Private Declare Function DeleteDC _
Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Sub Form_Load()
Call Me.Move(Me.Left, Me.Top, 6525, 1725)
Call Picture1.Move(120, 120, 6135, 495)
Call Command1.Move(4800, 720, 1465, 375)
Timer1.Interval = 10
Command1.Enabled = False
Command1.Caption = "&Sauvegarder"
Me.ScaleMode = vbPixels
Me.Caption = "Démo de sauvegarde d'image"
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = False
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Command1.Enabled = True
Call PrintWindow(FindWindow("Shell_TrayWnd", vbNullString),
Picture1.hDC, 0)
End Sub
Private Sub Command1_Click()
Const FILE_NAME As String = "c:picture1.bmp"
Call SavePictureBoxToBMP(Picture1.hDC, 0, 0, Picture1.ScaleWidth,
Picture1.ScaleHeight, FILE_NAME)
Call Shell("mspaint """ & FILE_NAME & """", vbNormalFocus)
End Sub
Public Sub SavePictureBoxToBMP( _
ByRef hDCSrc As Long, _
ByRef lPosX As Long, _
ByRef lPosY As Long, _
ByRef lWidth As Long, _
ByRef lHeight As Long, _
ByRef sFileName As String)
Dim hDC As Long
Dim hDIB As Long
Dim hOldDIB As Long
Dim biHeader As BITMAPINFOHEADER
Dim lScanLine As Long
Dim byDIB() As Byte
' initialise notre DC
hDC = CreateCompatibleDC(hDCSrc)
hDIB = CreateCompatibleBitmap(hDCSrc, lWidth, lHeight)
hOldDIB = SelectObject(hDC, hDIB)
' copie le contenu du DCSrc dans notre DC
Call BitBlt(hDC, 0, 0, lWidth, lHeight, hDCSrc, lPosX, lPosY,
' obtient l'entete du bitmap
biHeader = CreateBIHeader(lWidth, lHeight, byDIB)
' obtient les octets du DIB
Call GetDIBits(hDC, hDIB, 0, lHeight, byDIB(0, 0), biHeader, 0)
' sauvegarde le fichier
Call SaveFileAs(sFileName, biHeader, CreateBFHeader(biHeader), byDIB)
' Libère les ressources
Call SelectObject(hDC, hOldDIB)
Call DeleteObject(hDIB)
Call DeleteDC(hDC)
End Sub
Private Function CreateBIHeader( _
ByRef lWidth As Long, _
ByRef lHeight As Long, _
ByRef byDIB() As Byte) As BITMAPINFOHEADER
Dim lScanLine As Long
' prépare notre entete de bitmap
With CreateBIHeader
.biSize = Len(CreateBIHeader)
.biBitCount = 24
.biPlanes = 1
.blHeight = lHeight
.blWidth = lWidth
lScanLine = (((.blWidth * .biBitCount) + &H1F) And Not &H1F) &H8
.biSizeImage = lScanLine * .blHeight
ReDim byDIB(lScanLine - 1, CreateBIHeader.blHeight - 1) As Byte
End With
End Function
Private Function CreateBFHeader(ByRef biHeader As BITMAPINFOHEADER) As
BITMAPFILEHEADER
' initialise l'entete du fichier
With CreateBFHeader
.bfType = BMP_MAGIC_COOKIE
.bfOffBits = Len(CreateBFHeader) + Len(biHeader)
.bfSize = .bfOffBits + biHeader.biSizeImage
End With
End Function
Private Function SaveFileAs( _
ByRef sFileName As String, _
ByRef biHeader As BITMAPINFOHEADER, _
ByRef bfHeader As BITMAPFILEHEADER, _
ByRef byDIB() As Byte) As Boolean
Dim hFile As Long
' supprime le fichier s'il existe déjà
If (FileExists(sFileName)) Then
Call Kill(sFileName)
End If
' sauvegarde l'image dans le fichier
hFile = FreeFile
Open sFileName For Binary As #hFile
Put #hFile, , bfHeader
Put #hFile, , biHeader
Put #hFile, , byDIB
Close #hFile
End Function
Private Function FileExists(ByRef sFileName As String) As Boolean
On Error Resume Next
FileExists = ((GetAttr(sFileName) And vbDirectory) = 0)
End Function
'***
--
Cordialement
Yanick
MVP pour Visual Basic
naaaargg... tu travailles sur Win 9X c'est bien ça ? :OP
si c'est le cas, essai ceci... je ne peux malheureusement pas tester la
modification avant lundi.. :O/
'***
' Form 1
' 1 PictureBox
' 1 CommandButton
' 1 Timer
Option Explicit
' Constante désignant "BM" pour l'entête du fichier
Private Const BMP_MAGIC_COOKIE = &H4D42
' Information relative à l'entête du bitmap
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
blWidth As Long
blHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
' Information relative à l'entête du fichier
Private Type BITMAPFILEHEADER '14 bytes
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function CreateCompatibleDC _
Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Declare Function CreateCompatibleBitmap _
Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal nWidth As Long, _
ByVal nHeight 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 Declare Function GetDIBits _
Lib "gdi32" _
( _
ByVal hDC As Long, _
ByVal hBitmap As Long, _
ByVal nStartScan As Long, _
ByVal nNumScans As Long, _
ByRef lpBits As Any, _
ByRef lpBI As BITMAPINFOHEADER, _
ByVal wUsage As Long _
) As Long
Private Declare Function SelectObject _
Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal hObject As Long) As Long
Private Declare Function DeleteObject _
Lib "gdi32" ( _
ByVal hObject As Long) As Long
Private Declare Function DeleteDC _
Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Sub Form_Load()
Call Me.Move(Me.Left, Me.Top, 6525, 1725)
Call Picture1.Move(120, 120, 6135, 495)
Call Command1.Move(4800, 720, 1465, 375)
Timer1.Interval = 10
Command1.Enabled = False
Command1.Caption = "&Sauvegarder"
Me.ScaleMode = vbPixels
Me.Caption = "Démo de sauvegarde d'image"
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = False
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Command1.Enabled = True
Call BitBlt(Picture1.hDC, 0, 0, Picture1.ScaleWidth,
Picture1.ScaleHeight, _
FindWindow("Shell_TrayWnd", vbNullString), 0, 0,
vbSrcCopy)
End Sub
Private Sub Command1_Click()
Const FILE_NAME As String = "c:picture1.bmp"
Call SavePictureBoxToBMP(Picture1.hDC, 0, 0, Picture1.ScaleWidth,
Picture1.ScaleHeight, FILE_NAME)
Call Shell("mspaint """ & FILE_NAME & """", vbNormalFocus)
End Sub
Public Sub SavePictureBoxToBMP( _
ByRef hDCSrc As Long, _
ByRef lPosX As Long, _
ByRef lPosY As Long, _
ByRef lWidth As Long, _
ByRef lHeight As Long, _
ByRef sFileName As String)
Dim hDC As Long
Dim hDIB As Long
Dim hOldDIB As Long
Dim biHeader As BITMAPINFOHEADER
Dim lScanLine As Long
Dim byDIB() As Byte
' initialise notre DC
hDC = CreateCompatibleDC(hDCSrc)
hDIB = CreateCompatibleBitmap(hDCSrc, lWidth, lHeight)
hOldDIB = SelectObject(hDC, hDIB)
' copie le contenu du DCSrc dans notre DC
Call BitBlt(hDC, 0, 0, lWidth, lHeight, hDCSrc, lPosX, lPosY,
' obtient l'entete du bitmap
biHeader = CreateBIHeader(lWidth, lHeight, byDIB)
' obtient les octets du DIB
Call GetDIBits(hDC, hDIB, 0, lHeight, byDIB(0, 0), biHeader, 0)
' sauvegarde le fichier
Call SaveFileAs(sFileName, biHeader, CreateBFHeader(biHeader), byDIB)
' Libère les ressources
Call SelectObject(hDC, hOldDIB)
Call DeleteObject(hDIB)
Call DeleteDC(hDC)
End Sub
Private Function CreateBIHeader( _
ByRef lWidth As Long, _
ByRef lHeight As Long, _
ByRef byDIB() As Byte) As BITMAPINFOHEADER
Dim lScanLine As Long
' prépare notre entete de bitmap
With CreateBIHeader
.biSize = Len(CreateBIHeader)
.biBitCount = 24
.biPlanes = 1
.blHeight = lHeight
.blWidth = lWidth
lScanLine = (((.blWidth * .biBitCount) + &H1F) And Not &H1F) &H8
.biSizeImage = lScanLine * .blHeight
ReDim byDIB(lScanLine - 1, CreateBIHeader.blHeight - 1) As Byte
End With
End Function
Private Function CreateBFHeader(ByRef biHeader As BITMAPINFOHEADER) As
BITMAPFILEHEADER
' initialise l'entete du fichier
With CreateBFHeader
.bfType = BMP_MAGIC_COOKIE
.bfOffBits = Len(CreateBFHeader) + Len(biHeader)
.bfSize = .bfOffBits + biHeader.biSizeImage
End With
End Function
Private Function SaveFileAs( _
ByRef sFileName As String, _
ByRef biHeader As BITMAPINFOHEADER, _
ByRef bfHeader As BITMAPFILEHEADER, _
ByRef byDIB() As Byte) As Boolean
Dim hFile As Long
' supprime le fichier s'il existe déjà
If (FileExists(sFileName)) Then
Call Kill(sFileName)
End If
' sauvegarde l'image dans le fichier
hFile = FreeFile
Open sFileName For Binary As #hFile
Put #hFile, , bfHeader
Put #hFile, , biHeader
Put #hFile, , byDIB
Close #hFile
End Function
Private Function FileExists(ByRef sFileName As String) As Boolean
On Error Resume Next
FileExists = ((GetAttr(sFileName) And vbDirectory) = 0)
End Function
'***
--
Cordialement
Yanick
MVP pour Visual Basic
naaaargg... tu travailles sur Win 9X c'est bien ça ? :OP
si c'est le cas, essai ceci... je ne peux malheureusement pas tester la
modification avant lundi.. :O/
'***
' Form 1
' 1 PictureBox
' 1 CommandButton
' 1 Timer
Option Explicit
' Constante désignant "BM" pour l'entête du fichier
Private Const BMP_MAGIC_COOKIE = &H4D42
' Information relative à l'entête du bitmap
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
blWidth As Long
blHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
' Information relative à l'entête du fichier
Private Type BITMAPFILEHEADER '14 bytes
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function CreateCompatibleDC _
Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Declare Function CreateCompatibleBitmap _
Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal nWidth As Long, _
ByVal nHeight 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 Declare Function GetDIBits _
Lib "gdi32" _
( _
ByVal hDC As Long, _
ByVal hBitmap As Long, _
ByVal nStartScan As Long, _
ByVal nNumScans As Long, _
ByRef lpBits As Any, _
ByRef lpBI As BITMAPINFOHEADER, _
ByVal wUsage As Long _
) As Long
Private Declare Function SelectObject _
Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal hObject As Long) As Long
Private Declare Function DeleteObject _
Lib "gdi32" ( _
ByVal hObject As Long) As Long
Private Declare Function DeleteDC _
Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Sub Form_Load()
Call Me.Move(Me.Left, Me.Top, 6525, 1725)
Call Picture1.Move(120, 120, 6135, 495)
Call Command1.Move(4800, 720, 1465, 375)
Timer1.Interval = 10
Command1.Enabled = False
Command1.Caption = "&Sauvegarder"
Me.ScaleMode = vbPixels
Me.Caption = "Démo de sauvegarde d'image"
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = False
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Command1.Enabled = True
Call BitBlt(Picture1.hDC, 0, 0, Picture1.ScaleWidth,
Picture1.ScaleHeight, _
FindWindow("Shell_TrayWnd", vbNullString), 0, 0,
vbSrcCopy)
End Sub
Private Sub Command1_Click()
Const FILE_NAME As String = "c:picture1.bmp"
Call SavePictureBoxToBMP(Picture1.hDC, 0, 0, Picture1.ScaleWidth,
Picture1.ScaleHeight, FILE_NAME)
Call Shell("mspaint """ & FILE_NAME & """", vbNormalFocus)
End Sub
Public Sub SavePictureBoxToBMP( _
ByRef hDCSrc As Long, _
ByRef lPosX As Long, _
ByRef lPosY As Long, _
ByRef lWidth As Long, _
ByRef lHeight As Long, _
ByRef sFileName As String)
Dim hDC As Long
Dim hDIB As Long
Dim hOldDIB As Long
Dim biHeader As BITMAPINFOHEADER
Dim lScanLine As Long
Dim byDIB() As Byte
' initialise notre DC
hDC = CreateCompatibleDC(hDCSrc)
hDIB = CreateCompatibleBitmap(hDCSrc, lWidth, lHeight)
hOldDIB = SelectObject(hDC, hDIB)
' copie le contenu du DCSrc dans notre DC
Call BitBlt(hDC, 0, 0, lWidth, lHeight, hDCSrc, lPosX, lPosY,
' obtient l'entete du bitmap
biHeader = CreateBIHeader(lWidth, lHeight, byDIB)
' obtient les octets du DIB
Call GetDIBits(hDC, hDIB, 0, lHeight, byDIB(0, 0), biHeader, 0)
' sauvegarde le fichier
Call SaveFileAs(sFileName, biHeader, CreateBFHeader(biHeader), byDIB)
' Libère les ressources
Call SelectObject(hDC, hOldDIB)
Call DeleteObject(hDIB)
Call DeleteDC(hDC)
End Sub
Private Function CreateBIHeader( _
ByRef lWidth As Long, _
ByRef lHeight As Long, _
ByRef byDIB() As Byte) As BITMAPINFOHEADER
Dim lScanLine As Long
' prépare notre entete de bitmap
With CreateBIHeader
.biSize = Len(CreateBIHeader)
.biBitCount = 24
.biPlanes = 1
.blHeight = lHeight
.blWidth = lWidth
lScanLine = (((.blWidth * .biBitCount) + &H1F) And Not &H1F) &H8
.biSizeImage = lScanLine * .blHeight
ReDim byDIB(lScanLine - 1, CreateBIHeader.blHeight - 1) As Byte
End With
End Function
Private Function CreateBFHeader(ByRef biHeader As BITMAPINFOHEADER) As
BITMAPFILEHEADER
' initialise l'entete du fichier
With CreateBFHeader
.bfType = BMP_MAGIC_COOKIE
.bfOffBits = Len(CreateBFHeader) + Len(biHeader)
.bfSize = .bfOffBits + biHeader.biSizeImage
End With
End Function
Private Function SaveFileAs( _
ByRef sFileName As String, _
ByRef biHeader As BITMAPINFOHEADER, _
ByRef bfHeader As BITMAPFILEHEADER, _
ByRef byDIB() As Byte) As Boolean
Dim hFile As Long
' supprime le fichier s'il existe déjà
If (FileExists(sFileName)) Then
Call Kill(sFileName)
End If
' sauvegarde l'image dans le fichier
hFile = FreeFile
Open sFileName For Binary As #hFile
Put #hFile, , bfHeader
Put #hFile, , biHeader
Put #hFile, , byDIB
Close #hFile
End Function
Private Function FileExists(ByRef sFileName As String) As Boolean
On Error Resume Next
FileExists = ((GetAttr(sFileName) And vbDirectory) = 0)
End Function
'***
--
Cordialement
Yanick
MVP pour Visual Basic
naaaargg... tu travailles sur Win 9X c'est bien ça ? :OP
si c'est le cas, essai ceci... je ne peux malheureusement pas tester la
modification avant lundi.. :O/
'***
' Form 1
' 1 PictureBox
' 1 CommandButton
' 1 Timer
Option Explicit
' Constante désignant "BM" pour l'entête du fichier
Private Const BMP_MAGIC_COOKIE = &H4D42
' Information relative à l'entête du bitmap
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
blWidth As Long
blHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
' Information relative à l'entête du fichier
Private Type BITMAPFILEHEADER '14 bytes
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function CreateCompatibleDC _
Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Declare Function CreateCompatibleBitmap _
Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal nWidth As Long, _
ByVal nHeight 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 Declare Function GetDIBits _
Lib "gdi32" _
( _
ByVal hDC As Long, _
ByVal hBitmap As Long, _
ByVal nStartScan As Long, _
ByVal nNumScans As Long, _
ByRef lpBits As Any, _
ByRef lpBI As BITMAPINFOHEADER, _
ByVal wUsage As Long _
) As Long
Private Declare Function SelectObject _
Lib "gdi32" ( _
ByVal hDC As Long, _
ByVal hObject As Long) As Long
Private Declare Function DeleteObject _
Lib "gdi32" ( _
ByVal hObject As Long) As Long
Private Declare Function DeleteDC _
Lib "gdi32" ( _
ByVal hDC As Long) As Long
Private Sub Form_Load()
Call Me.Move(Me.Left, Me.Top, 6525, 1725)
Call Picture1.Move(120, 120, 6135, 495)
Call Command1.Move(4800, 720, 1465, 375)
Timer1.Interval = 10
Command1.Enabled = False
Command1.Caption = "&Sauvegarder"
Me.ScaleMode = vbPixels
Me.Caption = "Démo de sauvegarde d'image"
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = False
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Command1.Enabled = True
Call BitBlt(Picture1.hDC, 0, 0, Picture1.ScaleWidth,
Picture1.ScaleHeight, _
FindWindow("Shell_TrayWnd", vbNullString), 0, 0,
vbSrcCopy)
End Sub
Private Sub Command1_Click()
Const FILE_NAME As String = "c:picture1.bmp"
Call SavePictureBoxToBMP(Picture1.hDC, 0, 0, Picture1.ScaleWidth,
Picture1.ScaleHeight, FILE_NAME)
Call Shell("mspaint """ & FILE_NAME & """", vbNormalFocus)
End Sub
Public Sub SavePictureBoxToBMP( _
ByRef hDCSrc As Long, _
ByRef lPosX As Long, _
ByRef lPosY As Long, _
ByRef lWidth As Long, _
ByRef lHeight As Long, _
ByRef sFileName As String)
Dim hDC As Long
Dim hDIB As Long
Dim hOldDIB As Long
Dim biHeader As BITMAPINFOHEADER
Dim lScanLine As Long
Dim byDIB() As Byte
' initialise notre DC
hDC = CreateCompatibleDC(hDCSrc)
hDIB = CreateCompatibleBitmap(hDCSrc, lWidth, lHeight)
hOldDIB = SelectObject(hDC, hDIB)
' copie le contenu du DCSrc dans notre DC
Call BitBlt(hDC, 0, 0, lWidth, lHeight, hDCSrc, lPosX, lPosY,
' obtient l'entete du bitmap
biHeader = CreateBIHeader(lWidth, lHeight, byDIB)
' obtient les octets du DIB
Call GetDIBits(hDC, hDIB, 0, lHeight, byDIB(0, 0), biHeader, 0)
' sauvegarde le fichier
Call SaveFileAs(sFileName, biHeader, CreateBFHeader(biHeader), byDIB)
' Libère les ressources
Call SelectObject(hDC, hOldDIB)
Call DeleteObject(hDIB)
Call DeleteDC(hDC)
End Sub
Private Function CreateBIHeader( _
ByRef lWidth As Long, _
ByRef lHeight As Long, _
ByRef byDIB() As Byte) As BITMAPINFOHEADER
Dim lScanLine As Long
' prépare notre entete de bitmap
With CreateBIHeader
.biSize = Len(CreateBIHeader)
.biBitCount = 24
.biPlanes = 1
.blHeight = lHeight
.blWidth = lWidth
lScanLine = (((.blWidth * .biBitCount) + &H1F) And Not &H1F) &H8
.biSizeImage = lScanLine * .blHeight
ReDim byDIB(lScanLine - 1, CreateBIHeader.blHeight - 1) As Byte
End With
End Function
Private Function CreateBFHeader(ByRef biHeader As BITMAPINFOHEADER) As
BITMAPFILEHEADER
' initialise l'entete du fichier
With CreateBFHeader
.bfType = BMP_MAGIC_COOKIE
.bfOffBits = Len(CreateBFHeader) + Len(biHeader)
.bfSize = .bfOffBits + biHeader.biSizeImage
End With
End Function
Private Function SaveFileAs( _
ByRef sFileName As String, _
ByRef biHeader As BITMAPINFOHEADER, _
ByRef bfHeader As BITMAPFILEHEADER, _
ByRef byDIB() As Byte) As Boolean
Dim hFile As Long
' supprime le fichier s'il existe déjà
If (FileExists(sFileName)) Then
Call Kill(sFileName)
End If
' sauvegarde l'image dans le fichier
hFile = FreeFile
Open sFileName For Binary As #hFile
Put #hFile, , bfHeader
Put #hFile, , biHeader
Put #hFile, , byDIB
Close #hFile
End Function
Private Function FileExists(ByRef sFileName As String) As Boolean
On Error Resume Next
FileExists = ((GetAttr(sFileName) And vbDirectory) = 0)
End Function
'***
--
Cordialement
Yanick
MVP pour Visual Basic
je crois que cet exemple vien de allapi.net que j'ai essayer
mais sa fonctionne pas.
désoler pour ca mais je crois que les probleme est plus complexe que ca.
je crois que cet exemple vien de allapi.net que j'ai essayer
mais sa fonctionne pas.
désoler pour ca mais je crois que les probleme est plus complexe que ca.
je crois que cet exemple vien de allapi.net que j'ai essayer
mais sa fonctionne pas.
désoler pour ca mais je crois que les probleme est plus complexe que ca.
Salut !
> je crois que cet exemple vien de allapi.net que j'ai essayer
> mais sa fonctionne pas.
Peux-tu nous montrer ton code et nous expliquer dans quel contexte tu
emplois quels parties de mon exemple ?
> désoler pour ca mais je crois que les probleme est plus complexe que ca.
J'en doute... :O/
montre nous ce que tu as essayé... ;O)
--
Cordialement
Yanick
MVP pour Visual Basic
Salut !
> je crois que cet exemple vien de allapi.net que j'ai essayer
> mais sa fonctionne pas.
Peux-tu nous montrer ton code et nous expliquer dans quel contexte tu
emplois quels parties de mon exemple ?
> désoler pour ca mais je crois que les probleme est plus complexe que ca.
J'en doute... :O/
montre nous ce que tu as essayé... ;O)
--
Cordialement
Yanick
MVP pour Visual Basic
Salut !
> je crois que cet exemple vien de allapi.net que j'ai essayer
> mais sa fonctionne pas.
Peux-tu nous montrer ton code et nous expliquer dans quel contexte tu
emplois quels parties de mon exemple ?
> désoler pour ca mais je crois que les probleme est plus complexe que ca.
J'en doute... :O/
montre nous ce que tu as essayé... ;O)
--
Cordialement
Yanick
MVP pour Visual Basic