1

我创建了一个重新着色功能来重新着色我的图片框,

我的功能是红色的,它把一切都变成红色。

但现在我想输入一些滚动条功能来控制它。

如果我想要 3 个代表 R、G、B 的滚动条

我该如何根据我当前的功能做到这一点?

    Try
        ' Retrieve the image.
        image1 = New Bitmap("C:\Users\Anons\Desktop\Winter.jpg", True)

        Dim x, y As Integer

        ' Loop through the images pixels to reset color.
        For x = 0 To image1.Width - 1
            For y = 0 To image1.Height - 1
                Dim pixelColor As Color = image1.GetPixel(x, y)
                Dim newColor As Color = _
                    Color.FromArgb(pixelColor.R, 0, 0)
                image1.SetPixel(x, y, newColor)
            Next
        Next

        ' Set the PictureBox to display the image.
        PictureBox1.Image = image1

        ' Display the pixel format in Label1.
        Label1.Text = "Pixel format: " + image1.PixelFormat.ToString()

    Catch ex As ArgumentException
        MessageBox.Show("There was an error." _
            & "Check the path to the image file.")
    End Try
End Sub$
4

1 回答 1

0

您只需将所有三个颜色分量(R、G 和 B)乘以由滚动条确定的分数因子。例如,因子 1 将使其保持相同的颜色。0.5 的系数会使颜色亮度减半。2 倍的亮度会使亮度增加一倍,以此类推。

Dim rFactor As Single = rScroll.Value / 100
Dim gFactor As Single = gScroll.Value / 100
Dim bFactor As Single = bScroll.Value / 100
Dim newColor As Color = Color.FromArgb(pixelColor.R * rFactor, pixelColor.R * gFactor, pixelColor.B * bFactor)
于 2012-11-30T13:26:12.420 回答