Essai ce code en le mettant dans un module:
(Je ne cacherais pas que je le l'ai en majorité pompé)
Public Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Public Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Public Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Public Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Global PicBits() As Byte 'Passer ces deux variables aux fonctions.
Global PicInfo As BITMAP
Public Function CopierImage4(ByVal InPic As PictureBox, ByRef outPicBits() As Byte, ByRef OutPicInfo As BITMAP) As Integer
'
' Retourne
' 0 Ok
' autre Consulter liste erreurs VB
'
On Error GoTo ErrHndCI4
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'Page exacte: http://www.allapi.net/api/api018.php
Debug.Print "Début CopierImage4"
'Get information (such as height and width) about the picturebox
GetObject InPic.Image, Len(OutPicInfo), OutPicInfo
'reallocate storage space
ReDim outPicBits(0 To OutPicInfo.bmWidth * OutPicInfo.bmHeight * 3) As Byte
'Copy the bitmapbits to the array
GetBitmapBits InPic.Image, UBound(outPicBits), outPicBits(1)
Debug.Print "Fin CopierImage4"
Exit Function
ErrHndCI4:
CopierImage4 = Err.Number
End Function
Public Function CollerImage4(ByVal OutPic As PictureBox, ByRef inPicBits() As Byte, ByRef InPicInfo As BITMAP) As Integer
'
' Retourne
' 0 Ok
' 1 InPicBits vide
' autre Consulter liste erreurs VB
'
On Error GoTo ErrHndCollerI4
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'Page exacte: http://www.allapi.net/api/api018.php
Debug.Print "Début CollerImage4"
'Set the bits back to the picture
SetBitmapBits OutPic.Image, UBound(inPicBits), inPicBits(MKSBBBitsOffset)
'refresh
OutPic.Refresh
Debug.Print "Fin CollerImage4"
Exit Function
ErrHndCollerI4:
CollerImage4 = Err.Number
End Function