开发者

manipulating image

folks, i need to retri开发者_如何学运维eve colors of an image.. how to retrieve it?


if you load the image into a Bitmap class (System.Drawing.Bitmap), you can use GetPixel() method to retrieve color of individual pixels.


You can get the color of a certain pixel using Bitmap.GetPixel


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜