none
i need to control / check all of PictureBox image pixels color RRS feed

  • Question

  • i need to control / check all of PictureBox image pixels color in vb.net forms applicatoin 
    Wednesday, December 26, 2018 4:02 PM

All replies

  • i need to control / check all of PictureBox image pixels color in vb.net forms applicatoin 

    Hi

    What is the size(s) of the images you need to check/control? How many images? What do you mean by 'control' - change the poixel color perhaps?

    Are you aware that it can be a very lengthy operation for a large image. May need Threading to keep UI active.


    Regards Les, Livingston, Scotland

    Wednesday, December 26, 2018 4:43 PM
  • I want to creat program can give me the %  ol all colors in picture  box image 

    Example  

    You have in picture  

    30%red 

    30%yellow 

    40%black 

    Wednesday, December 26, 2018 4:56 PM
  • I want to creat program can give me the %  ol all colors in picture  box image 

    Example  

    You have in picture  

    30%red 

    30%yellow 

    40%black 

    Hi

    There are many color depths available. Some of the higher ones could have thousands. Would you be wanting a list of all of the percentages (thousands)?


    Regards Les, Livingston, Scotland

    Wednesday, December 26, 2018 5:04 PM
  • Hi,

    You can try following way:

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            TextBox1.Text = getfix(Color.Blue).ToString
            TextBox2.Text = getfix(Color.Green).ToString
            TextBox3.Text = getfix(Color.Red).ToString
        End Sub
        Public Function getfix(ByVal colo As Color) As Integer
            Dim p As Integer
            Dim _Bitmap As Bitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
            PictureBox1.DrawToBitmap(_Bitmap, New Rectangle(0, 0, PictureBox1.Width, PictureBox1.Height))
            Dim allPixels As Integer = PictureBox1.Width * PictureBox1.Height
            Dim redPixels As Integer = 0
            Dim col = colo
            Dim rRange = Enumerable.Range(0, 200)
            Dim gRange = Enumerable.Range(100, 255)
            Dim bRange = Enumerable.Range(50, 255)
    
            For i As Integer = 0 To PictureBox1.Width - 1 - 1
    
                For j As Integer = 0 To PictureBox1.Height - 1 - 1
                    Dim pixel = _Bitmap.GetPixel(i, j)
    
                    If col.R = pixel.R AndAlso col.G = pixel.G AndAlso col.B = pixel.B Then
                        redPixels += 1
                    End If
    
                    If rRange.Contains(pixel.R) AndAlso gRange.Contains(pixel.G) AndAlso bRange.Contains(pixel.B) Then
                        redPixels += 1
                    End If
                Next
            Next
            Return (((redPixels / allPixels) * 100).ToString())
    
        End Function
    End Class
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 27, 2018 5:21 AM