Pourquoi PSET est-il si lent ?

Résolu
Herve_be Messages postés 1015 Date d'inscription mercredi 4 août 2010 Statut Membre Dernière intervention 10 mars 2024 - 23 nov. 2018 à 10:34
Herve_be Messages postés 1015 Date d'inscription mercredi 4 août 2010 Statut Membre Dernière intervention 10 mars 2024 - 24 nov. 2018 à 18:03
Bonjour,
Je voudrais modifier une picturebox avec PSET, voici mon code : les variables R, G et B contiennent les valeurs de la couleur à peindre
Photo2.DrawMode = vbCopyPen

Photo2.ScaleWidth = Photo2.Width / 15 ' pour travailler en pixels
Photo2.ScaleHeight = Photo2.Height / 15 ' pour travailler en pixels

For x = 0 To Photo2.ScaleWidth
For y = 0 To Photo2.ScaleHeight
Photo2.PSet (x, y), RGB(R, G, B)
DoEvents
Next y
DoEvents
Next x
Le problème est que c'est vraiment très lent, plusieurs minutes pour une image de 800 x 600 pixels !
Une idée pour accélérer ?

2 réponses

NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 159
23 nov. 2018 à 12:59
Déjà, essayes sans les DoEvents.

Sinon, il y a peut être l'API SetPixel.
https://www.tannerhelland.com/41/vb-graphics-programming-2/
0
Herve_be Messages postés 1015 Date d'inscription mercredi 4 août 2010 Statut Membre Dernière intervention 10 mars 2024 2
24 nov. 2018 à 18:03
Pas de changement significatif sans les DoEvents Mais bien avec SetPixelV :
pour une image de 800 x 600 pixels : 58 secondes avec Pset, 0,9 seconde avec GDI !
Merci, problème résolu.

Pour info le but était d'étirer l'histogramme d'une photo, voici mon code
White et Black contiennent les références blanche et noire de la photo
le paramètre Refresh = Y permet de montrer la progression
Private Sub HistoStretch(Refresh As String)
HistoMax = MyMax(WhiteR, WhiteG, WhiteB)
HistoMin = MyMin(BlackR, BlackG, BlackB)
Alpha = 255 / (HistoMax - HistoMin)
Beta = -HistoMin * Alpha
Photo2.DrawMode = vbCopyPen
TimeStamp = Timer()
For y = 0 To Photo2.ScaleHeight
For x = 0 To Photo2.ScaleWidth

Pixel = GetPixel(Photo2.hdc, x, y)

R = Pixel And &HFF&
G = (Pixel And &HFF00&) \ &H100&
B = (Pixel And &HFF0000) \ &H10000

R = Alpha * R + Beta
G = Alpha * G + Beta
B = Alpha * B + Beta

If R >= 0 And G >= 0 And B >= 0 Then
Call SetPixelV(Photo2.hdc, x, y, RGB(R, G, B))
End If
Next x
If Refresh = "Y" Then Photo2.Refresh
Next y
TimeStamp = Timer() - TimeStamp
End Sub
0
Rejoignez-nous