Die vor einigen Tagen bereitgestellte Prozedur war etwas wurmig, hier die verbesserte Version.
''' <summary>
''' Erzeugt ein neues Bild welches ein zweites Bild unter Herausrechnung
' vom Hintergrund enthaelt.
''' </summary>
''' <param name="pImage">Ausgangsbild welches ergaenzt werden soll</param>
''' <param name="pAddOn">Zusatzbild welches hinzugefuegt werden soll</param>
''' <param name="pAddOnBackColor">Herauszurechnende Hintergrundfarbe vom
' Zusatzbild</param>
''' <param name="pDistanceThresHold">Farbdifferenz ab wann ein Pixel vom
' Zusatzbild als Hintergrund erkannt werden soll</param>
''' <param name="pOP1">Farbanteil, welcher vom Ausgangsbild pro Pixel in
' das neue Pixel einfliessen soll. 0 = 0%, 1 = 100%</param>
''' <param name="pOP2">Farbanteil, welcher vom Zusatzbild pro Pixel in
' das neue Pixel einfliesen soll. 0 = 0%, 1 = 100%</param>
''' <param name="pMergePoint">obere linke Ecke im Zielbild fuer das
' Zufuegen vom Zusatzbild</param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function Image2MergedImage( _
ByVal pImage As Image _
, ByVal pAddOn As Image _
, ByVal pAddOnBackColor As System.Drawing.Color _
, ByVal pDistanceThresHold As Single _
, ByVal pOP1 As Single _
, ByVal pOP2 As Single _
, ByVal pMergePoint As Point _
) As Image
' ---------------------------------------------------------------------
' -------------------------------------------
' Lokale Groessen
' ---------------------------------------------------------------------
' -------------------------------------------
'Arbeitsbereich fuer das Zielbild
Dim l_Destination As Bitmap = New Bitmap(pImage)
'Arbeitsbereich fuer den Bildzusatz
Dim l_AddOn As Bitmap = New Bitmap(pAddOn)
'Normalisierte Hintergrundfarbe des AddOn Bilds
Dim l_AddOnNBackColor As NRGB = RGBtoNRGB(pAddOnBackColor)
'Ein Bildpunkt aus dem AddOn Teil
Dim l_AddOnPixel As System.Drawing.Color
'ZielPixel, alter Wert
Dim l_DestinationPixelCurrent As System.Drawing.Color
'ZielPixel, neuer Wert
Dim l_DestinationPixelNew As System.Drawing.Color
'Zielpunkt x Koordinate
Dim l_DestinationX As Integer
'Zielpunkt y Koordinate
Dim l_DestinationY As Integer
'Zielbereich als Schnittbereich des Ueberlagerungsbilds angelegt am
' Einfuegepunkt und dem Zielbild
Dim l_DestinationRect As Rectangle = Rectangle.Intersect(New Rectangle( _
pMergePoint, pAddOn.Size), New Rectangle(New Point(0, 0), _
l_Destination.Size))
'Startpunkt zur Entnahme der Pixel aus dem Ueberlagerungsbild
Dim l_StartPoint As New Point(l_DestinationRect.X - pMergePoint.X, _
l_DestinationRect.Y - pMergePoint.Y)
'Endpunkt zur Entnahme der Pixel aus dem Ueberlagerungsbild
Dim l_EndPoint As New Point(l_StartPoint.X + l_DestinationRect.Width - _
1, l_StartPoint.Y + l_DestinationRect.Height - 1)
' ---------------------------------------------------------------------
' -------------------------------------------
' Verarbeitung
' ---------------------------------------------------------------------
' -------------------------------------------
For y As Integer = l_StartPoint.Y To l_EndPoint.Y
For x As Integer = l_StartPoint.X To l_EndPoint.X
'Zielpunkt ausrechnen
l_DestinationX = pMergePoint.X + x
l_DestinationY = pMergePoint.Y + y
'AddOnPixel ermitteln
l_AddOnPixel = l_AddOn.GetPixel(x, y)
'Farbdifferenz zum Hintergrund
If GetColorDistance(l_AddOnNBackColor, l_AddOnPixel) >= _
pDistanceThresHold Then
'Kein Hintergrundpixel => Bildpunkt mergen
'Bisheriges Zielpixel holen
l_DestinationPixelCurrent = l_Destination.GetPixel( _
l_DestinationX, l_DestinationY)
'Mischfarbe herstellen aus bisherigem Pixel und
' zuzufuegendem Pixel
l_DestinationPixelNew = GetBlendColor( _
l_DestinationPixelCurrent, pOP1, l_AddOnPixel, pOP2)
'Zielpixel mit neuem Inhalt versehen
l_Destination.SetPixel(l_DestinationX, l_DestinationY, _
l_DestinationPixelNew)
Else
'Farbdistanz ist zu Gross, somit Hintergrund Pixel, vergiss
' es
End If
Next
Next
Return l_Destination
End Function
Beitrag wurde zuletzt am 20.12.10 um 09:46:26 editiert. |