colorVal = GetPixel(GetDCInt, IndexCol, IndexLine)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionThe value of the hDC property can change while a program is running, so don't store the value in a variable; instead, use the hDC property each time you need it
Module GetPixel 'Declaration Public Function GetPixel( _ ByVal x As Integer, _ ByVal y As Integer _ ) As Color End Function Public Function ScanPicts(ByVal DirPict As String) As Integer Dim Aera As Long = 0 Dim Index As Long = 0 Dim NivGray As Integer = 0 Dim PRed As Integer = 0 Dim PGreen As Integer = 0 Dim PBlue As Integer = 0 Dim SomPx As Long = 0 Dim MyColor As Color Dim myBitmap As New Bitmap(DirPict) 'Scan de l'image Dim Width As Int32 = myBitmap.Width Dim Height As Int32 = myBitmap.Height Aera = Width * Height For y As Int32 = 0 To Height - 1 For x As Int32 = 0 To Width - 1 MyColor = myBitmap.GetPixel(x, y) PRed = MyColor.R PGreen = MyColor.G PBlue = MyColor.B 'Rc = Color.FromArgb(PRed, PGreen, PBlue) NivGray = (77 * PBlue + 151 * PGreen + 28 * PRed) / 256 Index = Index + 1 Tab.ProgressScan2.Value = (Index * 100) / Aera SomPx = SomPx + NivGray Next Next Tab.LabNbPixel2.Visible = True Tab.LabNbPixel2.Text = "Opération terminée: " & Index.ToString & " pixels scannés par image." ScanPicts = (SomPx / Index) End Function End Module
Module GetPixel 'Declaration Public Function GetPixel( _ ByVal x As Integer, _ ByVal y As Integer _ ) As Color End Function
return ScanPicts
à la fin de ta fonction ScanPicts
J'ai repris le code avec les API GetDC et GetPixel,
Tu dis avoir repris le code....Et??
Option Explicit Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function TranslateColor Lib "olepro32.dll" Alias "OleTranslateColor" (ByVal clr As OLE_COLOR, ByVal palet As Long, col As Long) As Long Private Sub Command1_Click() Dim toto As New StdPicture, i As Long, j As Long, couleur As Long Dim hdc As Long, R As Byte, G As Byte, B As Byte 'Picture1.Picture = LoadPicture("d:\bateau.bmp") ' <<<<===== ton image à toi ici, si tu traite picturebox et décommente 'Set toto = Picture1.Picture ' si tu veux partir d'une picturebox - et décommente Set toto = LoadPicture("d:\bateau.bmp") ' si tu veux partir d'un fichier . Inhibe sinon hdc = CreateCompatibleDC(0) SelectObject hdc, toto.Handle For i = 0 To toto.Width For j = 0 To toto.Height couleur = GetPixel(hdc, i, j) Dim RealColor As Long TranslateColor couleur, 0, RealColor R = RealColor And &HFF& G = (RealColor And &HFF00&) / 2 ^ 8 B = (RealColor And &HFF0000) / 2 ^ 16 MsgBox "R " & R & " G " & G & " B = " & B ' sors de cette boucle par CTRL + PAUSE Next j Next i End Sub
Picture1.Picture = LoadPicture("d:\bateau.bmp") ' <<<<===== ton image à toi ici, si tu traite picturebox et décommente Set toto = Picture1.Picture ' si tu veux partir d'une picturebox - et décommente ' Set toto = LoadPicture("d:\bateau.bmp") ' si tu veux partir d'un fichier . Inhibe sinon