操纵图像

发布于 2024-08-29 06:41:29 字数 29 浏览 1 评论 0原文

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

folks, i need to retrieve colors of an image.. how to retrieve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

幻想少年梦 2024-09-05 06:41:29

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

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

我只土不豪 2024-09-05 06:41:29

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

岁月静好 2024-09-05 06:41:29

实际上,这是 VB.NET,但使用 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文