操纵图像

时间:2010-04-16 06:32:37

标签: c# image-manipulation

伙计们,我需要检索图像的颜色..如何检索它?

4 个答案:

答案 0 :(得分:1)

如果将图像加载到Bitmap类(System.Drawing.Bitmap)中, 您可以使用GetPixel()方法检索单个像素的颜色。

答案 1 :(得分:1)

您可以使用Bitmap.GetPixel

获取某个像素的颜色

答案 2 :(得分:1)

实际上,这是VB.NET,但使用http://www.developerfusion.com/tools/convert/vb-to-csharp/

将其转换为c#
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

答案 3 :(得分:0)

这里有一些很好的信息:http://www.bobpowell.net/faqmain.htm