Вы находитесь на странице: 1из 2

Public Class Form3

Dim histogramValues(256)
Dim histogramValuesB(256)
Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As Sys
tem.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
TextBox1.Text = HScrollBar1.Value
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Dim nilaikontras As Integer = HScrollBar1.Value
Dim i, j As Integer
Dim gambar As New Bitmap(PictureBox1.Image)
PictureBox2.Image = gambar
Dim gambar2 As New Bitmap(PictureBox1.Image)
PictureBox1.Image = gambar2
Dim r, g, b As Integer
Dim x, xb As Double
For i = 0 To gambar.Width - 1
For j = 0 To gambar.Height - 1
r = gambar.GetPixel(i, j).R
g = gambar.GetPixel(i, j).G
b = gambar.GetPixel(i, j).B
x = ((r + g + b) / 3)
gambar2.SetPixel(i, j, Color.FromArgb(x, x, x))
xb = nilaikontras * (r - x) + x
If (xb > 255) Then
xb = 255
ElseIf (xb < 0) Then
xb = 0
End If
gambar.SetPixel(i, j, Color.FromArgb(xb, xb, xb))
Next j
Next i
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button2.Click
ReDim histogramValues(256)
Dim bmp As New Bitmap(PictureBox1.Image, PictureBox1.Width, PictureBox1.
Height)
Dim bmp2 As New Bitmap(PictureBox2.Image, PictureBox2.Width, PictureBox2
.Height)
PictureBox1.DrawToBitmap(bmp, PictureBox1.ClientRectangle)
PictureBox2.DrawToBitmap(bmp2, PictureBox2.ClientRectangle)
PictureBox1.Image = bmp
PictureBox2.Image = bmp2
For y As Integer = 0 To bmp.Height - 1
For x As Integer = 0 To bmp.Width - 1
Dim r As Integer = bmp.GetPixel(x, y).R
Dim g As Integer = bmp.GetPixel(x, y).G
Dim b As Integer = bmp.GetPixel(x, y).B
Dim Rumus As Single = ((r + g + b) / 3)
histogramValues(Rumus + 1) = histogramValues(Rumus + 1) + 1
bmp.SetPixel(x, y, Color.FromArgb(Rumus, Rumus, Rumus))
Next
Next
PictureBox3.Invalidate()
For y As Integer = 0 To bmp2.Height - 1
For x As Integer = 0 To bmp2.Width - 1
Dim r As Integer = bmp2.GetPixel(x, y).R
Dim g As Integer = bmp2.GetPixel(x, y).G

Dim b As Integer = bmp2.GetPixel(x, y).B


Dim Rumus As Single = (r + g + b) / 3
histogramValuesB(Rumus + 1) = histogramValuesB(Rumus + 1) + 1
bmp2.SetPixel(x, y, Color.FromArgb(Rumus, Rumus, Rumus))
Next
Next
PictureBox4.Invalidate()
End Sub
Private Sub PictureBox4_Paint(ByVal sender As System.Object, ByVal e As Syst
em.Windows.Forms.PaintEventArgs) Handles PictureBox4.Paint
If histogramValuesB.Max <= 0 Then Exit Sub
Dim h As Integer = PictureBox4.ClientSize.Height
For i As Integer = 0 To 255 Step 2
Dim barHeight As Integer = _
CInt(h * histogramValuesB(i) / histogramValuesB.Max)
Dim x As Integer = (PictureBox4.ClientSize.Width * i) \ 256
Using pn As New Pen(Brushes.Blue, 2)
e.Graphics.DrawLine(pn, x, h - barHeight, x, h)
End Using
Next
End Sub
Private Sub PictureBox3_Paint(ByVal sender As System.Object, ByVal e As Syst
em.Windows.Forms.PaintEventArgs) Handles PictureBox3.Paint
If histogramValues.Max <= 0 Then Exit Sub
Dim h As Integer = PictureBox3.ClientSize.Height
For i As Integer = 0 To 255 Step 2
Dim barHeight As Integer = _
CInt(h * histogramValues(i) / histogramValues.Max)
Dim x As Integer = (PictureBox3.ClientSize.Width * i) \ 256
Using pn As New Pen(Brushes.Blue, 2)
e.Graphics.DrawLine(pn, x, h - barHeight, x, h)
End Using
Next
End Sub
End Class

Вам также может понравиться