我创建了一个重新着色功能来重新着色我的图片框,
我的功能是红色的,它会把所有东西变成红色。
但现在我想输入一些滚动条功能来控制它。
如果我想要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$
答案 0 :(得分: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)