'NivGray = (77 * PBlue + 151 * PGreen + 28 * PRed) / 256 NivGray = CInt((77 * PBlue + 151 * PGreen + 28 * PRed) / 256) 'Et: 'ScanPicts = (SomPx / Index) ScanPicts = CInt(SomPx / Index)
Public Function MaSomme(ByVal ValA As Integer, ByVal ValB As Integer) As Integer Return ValA + ValB End Function 'Et pour l’appeler: Dim MaValeur As Integer = MaSomme(4, 2) MessageBox.Show(MaValeur.ToString)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionVous pouvez exploiter le fait qu'un bitmap peut être mis dans un formulaire ou un PictureBox
Dim Image1 As New Form Image1.BackgroundImage = Image.FromFile("c:\users\toto\desktop\test.jpg") Image1.BackgroundImageLayout = ImageLayout.Center Image1.FormBorderStyle = Windows.Forms.FormBorderStyle.None Image1.Show() Image1.BringToFront()
GetDCInt = GetDC(0&) ... colorVal = GetPixel(GetDCInt, Zone.Left + IndexCol, Zone.Top + IndexLine)
Public Class Form1 Private WithEvents timer1 As New Windows.Forms.Timer Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load timer1.Interval = 10 timer1.Start() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles timer1.Tick Using bmp As New Bitmap(1, 1) Using g As Graphics = Graphics.FromImage(bmp) g.CopyFromScreen(Windows.Forms.Cursor.Position, _ New Point(0, 0), New Size(1, 1)) End Using Me.Text = bmp.GetPixel(0, 0).ToString Me.Invalidate() End Using End Sub End Class
1) Je ne vois absolument pas ce que le fait de passer de XP à Win 7 viendrait changer quoi que ce soit à la vitesse d'exécution d'une boucle !
3) d'une machine à l'autre (et pour une même "zone", ce ne sera pas l'OS, qui sera responsable d'une différence de temps d'exécution, mais d'autres facteurs, parmi lesquels :
- le processeur (ses performances)
- la carte graphique (ses performances)
- la mémoire vive restant disponible à un instant t S
6) je regrette de constater (mais cette remarque n'est qu'accessoire, au passage) que l'on force à relire en boucle une valeur, comme ici :
colorVal = GetPixel(GetDCInt, Zone.Left + IndexCol, Zone.Top + IndexLine)
Le processeur préfèrerait deux variables toto zone.left et titi Zone.top (et donc déterminées une seule fois)
7) Il serait nettement plus adroit de ne pas travailler sur tout l'écran (GetDC(0&)) mais sur la seule surface qui intéresse (un createdc serait le bienvenu)
Je ne vois pas encore comment, mais je vais y travailler.
' FONCTION PERMETTANT DE CAPTURER UNE IMAGE DU BUREAU SOUS UN FORMULAIRE ************************************************************* Public Sub FormShoot(ByVal mZone As Windows.Forms.Form, ByVal Fname As String) Try Dim bmpSS As Bitmap Dim gfxSS As Graphics Dim mFileName As String = Application.StartupPath & "\TEMP" & Fname & ".jpg" 'Si le fichier temporaire existe -> Delete If System.IO.File.Exists(mFileName) Then System.IO.File.Delete(mFileName) End If 'mZone, rectangle à capturer bmpSS = New Bitmap(mZone.Width, mZone.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb) gfxSS = Graphics.FromImage(bmpSS) gfxSS.CopyFromScreen(mZone.Location, New Point(0, 0), mZone.Size, CopyPixelOperation.SourceCopy) 'mFileName, pour le nom du fichier de destination bmpSS.Save(mFileName, System.Drawing.Imaging.ImageFormat.Jpeg) gfxSS.Dispose() bmpSS.Dispose() Catch ex As Exception WriteLog("Error: Function - " & System.Reflection.MethodBase.GetCurrentMethod().Name & " - " & Date.Now & " - " & ex.Message) End Try End Sub ' FONCTION PERMETTANT DE SCANNER UNE IMAGE PIXEL/PIXEL ********************************************************************************* 'Declaration Public Function GetPixel( _ ByVal x As Integer, _ ByVal y As Integer _ ) As Color End Function Public Function ScanPicts(ByVal DirPict As String, ByVal PctDest As PictureBox) 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 Try 'Ouvrir le fichier et afficher l'apercu Using reader As New IO.FileStream(DirPict, IO.FileMode.Open) PctDest.BackgroundImage = Image.FromStream(reader) End Using Dim myBitmap As New Bitmap(DirPict) 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 NivGray = (77 * PBlue + 151 * PGreen + 28 * PRed) / 256 Index = Index + 1 Tab.ProgressScan2.Value = (Index * 100) / Aera SomPx = SomPx + NivGray Next Next myBitmap.Dispose() myBitmap = Nothing ScanPicts = (SomPx / Index) Catch ex As Exception WriteLog("Error: Function - " & System.Reflection.MethodBase.GetCurrentMethod().Name & " - " & Date.Now & " - " & ex.Message) ScanPicts = 0 End Try End Function
Depuis, jimy a préféré revenir aux API et l'on ne sait pas trop pourquoi.