Couleurs des pixels d'un formulaire

Résolu
Zermelo - 5 déc. 2012 à 09:06
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 - 5 déc. 2012 à 20:58
Bonjour à tous.

Comment relever les couleurs des pixels d'un formulaire ?

Merci de bien vouloir me répondre.


Étant illettré, je signe d'une croix : ×

8 réponses

cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
5 déc. 2012 à 18:42
j'ai oublié la coloration syntaxique

Private Function Capturectrl(ByVal ctrl As Control) As Bitmap
        Dim memoryImage As Bitmap
        Dim memoryGraphics As Graphics
        memoryImage = Nothing
        Dim mygraphics As Graphics = ctrl.CreateGraphics()
        Dim s As Size = ctrl.Size
        If TypeOf ctrl Is Form AndAlso DirectCast(ctrl, Form).FormBorderStyle <> FormBorderStyle.None Then
            memoryImage = New Bitmap(s.Width - 10, s.Height - (SystemInformation.FrameBorderSize.Width + 6 + SystemInformation.CaptionHeight), mygraphics)
            memoryGraphics = Graphics.FromImage(memoryImage)
            memoryGraphics.CopyFromScreen(0, (SystemInformation.FrameBorderSize.Width + 0 + SystemInformation.CaptionHeight), 0, 0, New Size(memoryImage.Width, memoryImage.Height), CopyPixelOperation.SourceCopy)
        Else
            memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
            memoryGraphics = Graphics.FromImage(memoryImage)
            memoryGraphics.CopyFromScreen(ctrl.Left, ctrl.Top, 0, 0, New Size(memoryImage.Width, memoryImage.Height), CopyPixelOperation.SourceCopy)
        End If
        Return memoryImage
    End Function

    Private Function readbitmap(ByVal imagescan As Bitmap) As List(Of Color)

        Dim listpixel As New List(Of Color)
        Dim colorpixel As Color
        Try
            For row As Integer = 0 To imagescan.Width - 1
                For col As Integer = 0 To imagescan.Height - 1
                    colorpixel = imagescan.GetPixel(row, col)
                    listpixel.Add(colorpixel)
                Next
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        Return listpixel
    End Function

Dim lispixel As New List(Of Color)
    lispixel = readbitmap(Capturectrl(Me))

3
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 4
5 déc. 2012 à 10:52
Bonjour Zemelo


... Comment relever les couleurs des pixels...



Pourquoi "relever", sont-ils couchés


Dim r, v, b As String ' copie
r = Mid((Me.BackColor.ToArgb() And &HFFFFFF&).ToString("X"), 1, 2)
v = Mid((Me.BackColor.ToArgb() And &HFFFFFF&).ToString("X"), 3, 2)
b = Mid((Me.BackColor.ToArgb() And &HFFFFFF&).ToString("X"), 5, 2)
Dim r1 As Int32 = Convert.ToInt32(rougeS, 16) ' r, v, b
Dim v1 As Int32 = Convert.ToInt32(vertS, 16)
Dim b1 As Int32 = Convert.ToInt32(bleuS, 16)



Ceci te va-t-il ?

Cordialement, Joe.
0
Merci pour ta réponse, Joe, et aussi pour ton humour.

Je m'aperçois que j'aurais dû préciser que ce prélèvement peut avoir lieu après que l'on ait dessiné sur le formulaire.


Étant illettré, je signe d'une croix : ×
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
5 déc. 2012 à 17:28
Bonjour,
ta réponse est là ===>> Tapez le texte de l'url ici.


________________________
Réponse exacte ? => "REPONSE ACCEPTEE" facilitera les recherches.
Pas d'aide en ligne installée ? => ne comptez pas sur moi pour simplement répéter son contenu. Je n'interviendrai que si nécessité de la compléter.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Bonjour ucfoutu.

Le code que tu proposes

Private Sub GetPixel_Example(ByVal e As PaintEventArgs)
    Dim myBitmap As New Bitmap("Grapes.jpg")
    Dim pixelColor As Color = myBitmap.GetPixel(50, 50)
    Dim pixelBrush As New SolidBrush(pixelColor)
    e.Graphics.FillRectangle(pixelBrush, 0, 0, 100, 100)
End Sub


prélève la couleur d'un pixel d'un bitmap que l'on dessine ensuite sur quelque chose qui n'est pas précisé mais qui peut fort bien être un formulaire.
Mais c'est l'inverse que je veux faire : dessiner sur le formulaire par des procédures élémentaires, notamment du texte, puis relever les pixels du formulaire.

Amicales salutations.


Étant illettré, je signe d'une croix : ×
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
5 déc. 2012 à 18:39
Salut

peut etre compliqué bon

Private Function Capturectrl(ByVal ctrl As Control) As Bitmap
Dim memoryImage As Bitmap
Dim memoryGraphics As Graphics
memoryImage = Nothing
Dim mygraphics As Graphics = ctrl.CreateGraphics()
Dim s As Size = ctrl.Size
If TypeOf ctrl Is Form AndAlso DirectCast(ctrl, Form).FormBorderStyle <> FormBorderStyle.None Then
memoryImage = New Bitmap(s.Width - 10, s.Height - (SystemInformation.FrameBorderSize.Width + 6 + SystemInformation.CaptionHeight), mygraphics)
memoryGraphics = Graphics.FromImage(memoryImage)
memoryGraphics.CopyFromScreen(0, (SystemInformation.FrameBorderSize.Width + 0 + SystemInformation.CaptionHeight), 0, 0, New Size(memoryImage.Width, memoryImage.Height), CopyPixelOperation.SourceCopy)
Else
memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
memoryGraphics = Graphics.FromImage(memoryImage)
memoryGraphics.CopyFromScreen(ctrl.Left, ctrl.Top, 0, 0, New Size(memoryImage.Width, memoryImage.Height), CopyPixelOperation.SourceCopy)
End If
Return memoryImage
End Function

Private Function readbitmap(ByVal imagescan As Bitmap) As List(Of Color)

Dim listpixel As New List(Of Color)
Dim colorpixel As Color
Try
For row As Integer = 0 To imagescan.Width - 1
For col As Integer = 0 To imagescan.Height - 1
colorpixel = imagescan.GetPixel(row, col)
listpixel.Add(colorpixel)
Next
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return listpixel
End Function

Dim lispixel As New List(Of Color)
lispixel = readbitmap(Capturectrl(Me))
0
Bonsoir et merci ShayW.

C'est effectivement compliqué. Je vais étudier cela à tête reposée. Toutefois un coup d'œil rapide me donne à penser que vous faites une capture d'écran. Je vais essayer d'adapter cela à la comparaison des rendus de deux manières de construire un bitmap contenant du texte :
a) en dessinant directement ce texte sur le bitmap par DrawText
b) en dessinant ce texte sur un formulaire par DrawText puis en construisant le bitmap par ce que je crois être une capture d'écran.
Je subodore que le rendu est meilleur dans le second cas.

Cordialement.


Étant illettré, je signe d'une croix : ×
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
5 déc. 2012 à 20:58
en faite j'ai essayé sans capture d'écran
ainsi

 Dim formbitmap As New Bitmap(Me.Width, Me.Height)
        Me.DrawToBitmap(formbitmap, New Rectangle(0, 0, Me.Width, Me.Width))
        Dim lispixel As New List(Of Color)
        lispixel = readbitmap(formbitmap)


ici

cela m'a donné toutes les pixel couleur 0,0,0
0
Rejoignez-nous