Probiere ....
Public Class frmPicParam2
Dim fh As Integer = 550
Private WithEvents btnload As New Button With _
{.Parent = Me, .TextAlign = ContentAlignment.MiddleLeft, _
.Text = "B C G &Laden", .Width = 150}
Private WithEvents vsBright As New VScrollBar With _
{.Parent = Me, .Top = 20, .Height = fh}
Private WithEvents vsCont As New VScrollBar With _
{.Parent = Me, .Top = 20, .Height = fh, .Left = 25}
Private WithEvents vsGam As New VScrollBar With _
{.Parent = Me, .Top = 20, .Height = fh, .Left = 50}
Private pbOrg As New PictureBox With _
{.Parent = Me, .SizeMode = PictureBoxSizeMode.Zoom, _
.Top = 20, .Height = fh, .Left = 75, .Width = 300}
Private pbModified As New PictureBox With _
{.Parent = Me, .SizeMode = PictureBoxSizeMode.Zoom, _
.Top = 20, .Height = fh, .Left = 390, .Width = 300}
Private ofd As New OpenFileDialog With _
{.Title = "Bilddatei", _
.Filter = "Bild |*.jpg;*.gif;*.png;*.bmp;*.tif"}
Private Function SetBrightnessContrastGamma _
(ByVal InBitmap As Bitmap, _
ByVal Bright As Single, _
ByVal Cont As Single, _
ByVal Gam As Single) As Bitmap
If InBitmap Is Nothing Then Return Nothing
If Bright > 1 Then Bright = 1
If Bright < -1 Then Bright = -1
If Cont > 1 Then Cont = 1
If Cont < -1 Then Cont = -1
If Gam = 0 Then Gam = CSng(Gam + 1.0E-45)
Dim Diff As Single = (Bright / 2) - (Cont / 2)
Dim Matrix As New Imaging.ColorMatrix(New Single()() _
{New Single() {1 + Cont, 0, 0, 0, 0}, _
New Single() {0, 1 + Cont, 0, 0, 0}, _
New Single() {0, 0, 1 + Cont, 0, 0}, _
New Single() {0, 0, 0, 1, 0}, _
New Single() {Bright + Diff, _
Bright + Diff, _
Bright + Diff, 0, 1}})
Dim NewBmp As Bitmap
With InBitmap
NewBmp = New Bitmap(.Width, .Height, PixelFormat.Format24bppRgb)
Using ImageAttr As New Imaging.ImageAttributes(), _
NewBmpGra As Graphics = Graphics.FromImage(NewBmp)
ImageAttr.SetColorMatrix(Matrix)
ImageAttr.SetGamma(Gam)
NewBmpGra.DrawImage(InBitmap, _
New Rectangle(0, 0, .Width, .Height), _
0, 0, .Width, .Height, _
GraphicsUnit.Pixel, ImageAttr)
End Using
End With
Return NewBmp
End Function
Private Sub ChangeParam()
With pbModified
If Not .Image Is Nothing Then
.Image.Dispose()
.Image = Nothing
End If
End With
With pbOrg
pbModified.Image = SetBrightnessContrastGamma( _
CType(.Image, Bitmap), _
CSng(vsBright.Value / 100), _
CSng(vsCont.Value / 100), _
CSng(vsGam.Value / 1000))
End With
End Sub
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
Me.Width = 700
Me.Height = fh + 50
vsBright.Minimum = -100
vsCont.Minimum = -100
vsGam.Maximum = 2000
vsGam.Value = 1000
End Sub
Private Sub hsScroll(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.ScrollEventArgs) _
Handles vsBright.Scroll, vsCont.Scroll, vsGam.Scroll
ChangeParam()
End Sub
Private Sub btnload_Click _
(sender As Object, e As System.EventArgs) Handles btnload.Click
With ofd
If .ShowDialog = DialogResult.Cancel Then Exit Sub
Try
With pbOrg
If Not .Image Is Nothing Then
.Image.Dispose()
.Image = Nothing
End If
Using bmp_in As New Bitmap(ofd.FileName), _
bmp As New Bitmap(bmp_in.Width, bmp_in.Height, _
Imaging.PixelFormat.Format24bppRgb), _
gr As Graphics = Graphics.FromImage(bmp)
gr.DrawImage(bmp_in, 0, 0, bmp_in.Width, bmp_in.Height)
.Image = CType(bmp.Clone, Bitmap)
End Using
vsBright.Value = 0
vsCont.Value = 0
vsGam.Value = 1000
ChangeParam()
End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
End With
End Sub
End Class |