1

画像ボックスの色を変更するための色変更関数を作成します。

私の関数は赤で動作し、すべてが赤に変わります。

しかし今、私はそれを制御するためにいくつかのスクロールバー関数を入力したいと思います。

R、G、Bを表す3つのスクロールバーが必要な場合

現在の関数に基づいてそれを行うにはどうすればよいですか?

    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

3 つの色成分 (R、G、および B) すべてに、スクロール バーによって決定される分数を乗算するだけです。たとえば、係数が 1 の場合、同じ色が維持されます。0.5 倍すると、色の明るさが半分になります。係数 2 では、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 に答える