PictureBox изменить яркость и контрастность картинки - Visual Basic .NET
Формулировка задачи:
Элемент управления PicterBox как задать программно сохранение картинки с параметрами яркость, контрастность и другие характеристики при редактировании изображения? Спасибо.
Решение задачи: «PictureBox изменить яркость и контрастность картинки»
textual
Листинг программы
Imports System.Drawing.Imaging Public Class Form2 Private bmp, bmp2 As Bitmap Private rr, gg, bb, gm As Single Private isLoad As Boolean Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load bmp = loadBitmap("tst3.jpg") If bmp IsNot Nothing Then bmp2 = bmp.Clone PictureBox1.Image = bmp PictureBox2.Image = bmp2 TrackBar1.Minimum = 0 TrackBar1.Maximum = 50 TrackBar1.Value = 10 TrackBar2.Minimum = 1 TrackBar2.Maximum = 50 TrackBar2.Value = 10 isLoad = True End If End Sub Private Function loadBitmap(ByVal fileName As String) As Bitmap If Not IO.File.Exists(fileName) Then Return Nothing Using bm As Bitmap = New Bitmap(fileName) Return New Bitmap(bm) End Using End Function Private Sub TrackBar1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles TrackBar1.ValueChanged rr = TrackBar1.Value / 10 Label2.Text = rr.ToString End Sub Private Sub BrightnessGamma_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click PictureBox2.Image = colorProcessing(bmp2, rr, rr, rr, gm) End Sub Private Function colorProcessing(ByVal img As Bitmap, ByVal rr As Single, ByVal gg As Single, ByVal bb As Single, ByVal Gamma As Single) As Bitmap Dim copy As Bitmap = New Bitmap(img.Width, img.Height) Dim ia As ImageAttributes = New ImageAttributes Dim myColorMatrix As New ColorMatrix With myColorMatrix .Matrix00 = rr .Matrix11 = gg .Matrix22 = bb .Matrix33 = 1.0 .Matrix44 = 1.0 End With ia.SetColorMatrix(myColorMatrix) ia.SetGamma(Gamma) Dim g As Graphics = Graphics.FromImage(copy) g.DrawImage(img, New Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia) g.Dispose() Return copy End Function Private Sub TrackBar2_ValueChanged(sender As System.Object, e As System.EventArgs) Handles TrackBar2.ValueChanged gm = TrackBar2.Value / 10 Label3.Text = gm.ToString End Sub End Class
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д