vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
vb@rchiv Offline-Reader - exklusiv auf der vb@rchiv CD Vol.4  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Fortgeschrittene
Re: Schnelle Umrechnung eines Farbbildes in ein Graustufenbild in VB.NET 
Autor: Manfred X
Datum: 28.12.14 10:36

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
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Schnelle Umrechnung eines Farbbildes in ein Graustufenbild i...1.357Rainer19.12.14 15:31
Re: Schnelle Umrechnung eines Farbbildes in ein Graustufenbi...852Manfred X19.12.14 17:24
Re: Schnelle Umrechnung eines Farbbildes in ein Graustufenbi...784Rainer23.12.14 17:07
Re: Schnelle Umrechnung eines Farbbildes in ein Graustufenbi...894Manfred X23.12.14 17:55
Re: Schnelle Umrechnung eines Farbbildes in ein Graustufenbi...821Rainer24.12.14 12:07
Re: Schnelle Umrechnung eines Farbbildes in ein Graustufenbi...795Rainer27.12.14 14:18
Re: Schnelle Umrechnung eines Farbbildes in ein Graustufenbi...840Manfred X28.12.14 10:36
Re: Schnelle Umrechnung eines Farbbildes in ein Graustufenbi...770Rainer30.12.14 17:40
Re: Schnelle Umrechnung eines Farbbildes in ein Graustufenbi...792GPM23.12.14 18:04
Re: Schnelle Umrechnung eines Farbbildes in ein Graustufenbi...825effeff28.12.14 17:28

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2024 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel