folks, i need to retrieve colors of an image.. how to retrieve it?
+1
A:
if you load the image into a Bitmap class (System.Drawing.Bitmap), you can use GetPixel() method to retrieve color of individual pixels.
Axarydax
2010-04-16 06:37:58
A:
@sam you will get the colors of image pixel wise but it wont give you the same colors.
Chirag
2010-04-16 06:51:55
A:
There is some good info here: http://www.bobpowell.net/faqmain.htm
Mark Redman
2010-04-16 06:57:27
+1
A:
Actually, this is VB.NET, but convert it to c# using http://www.developerfusion.com/tools/convert/vb-to-csharp/
Private Sub btnOverlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOverlay.Click
Dim rgbColour = New Color
Dim bmpPicture As Bitmap = Nothing
Dim bmpPicture_Negative As Bitmap = Nothing
Try
bmpPicture = New Bitmap("/root/Desktop/head.jpg")
bmpPicture_Negative = New Bitmap("/root/Desktop/head.jpg")
Catch ex As Exception
MsgBox("One of the images is not present.")
End Try
Dim rectPicSize As System.Drawing.RectangleF = bmpPicture.GetBounds(System.Drawing.GraphicsUnit.Pixel)
Dim iMaxX As Integer = CInt(rectPicSize.Width)
Dim iMaxY As Integer = CInt(rectPicSize.Height)
Dim iYindex As Integer = 0
Dim iXindex As Integer = 0
For iYindex = 0 To iMaxY - 1 Step 1
For iXindex = 0 To iMaxX - 1 Step 1
rgbColour = bmpPicture.GetPixel(iXindex, iYindex)
rgbColour = Color.FromArgb(255 - rgbColour.R, 255 - rgbColour.G, 255 - rgbColour.B)
bmpPicture_Negative.SetPixel(iXindex, iYindex, rgbColour)
Next iXindex
Next iYindex
Dim strHTMLColor As String = System.Drawing.ColorTranslator.ToHtml(rgbColour)
TextBox1.Text = Nothing
TextBox1.Text = "R: "
TextBox1.Text += rgbColour.R.ToString() + vbCrLf
TextBox1.Text += "G: " + rgbColour.G.ToString() + vbCrLf
TextBox1.Text += "B: " + rgbColour.B.ToString() + vbCrLf
TextBox1.Text += "HTML: " + strHTMLColor + vbCrLf
PictureBox1.Image = bmpPicture
PictureBox2.Image = bmpPicture_Negative
'bmpPicture.Dispose()
End Sub
Quandary
2010-04-16 07:28:32