Sprache: VB
Diese Funktion ändert die Farbe aller Pixel mit einer bestimmten Farben in einer neuen Farbe.
''' <summary>
''' Diese Funktion ändert die Farbe aller Pixel mit einer bestimmten Farben in einer neuen Farbe
''' </summary>
''' <param name="SourceImage">Das Bild dessen Pixel neu gezeichnet werden sollen</param>
''' <param name="OldColor">Die alte Farbe</param>
''' <param name="NewColor">Die neue Farbe</param>
Public Function PixelRePaint(ByVal SourceImage As Image, ByVal OldColor As Color, ByVal NewColor As Color) As Bitmap
Dim NewBitmap As New Bitmap(SourceImage.Width, SourceImage.Height)
Dim CMap(0) As ColorMap
CMap(0) = New ColorMap
CMap(0).OldColor = OldColor
CMap(0).NewColor = NewColor
Dim ImgAttr As New ImageAttributes
ImgAttr.SetRemapTable(CMap)
Using G As Graphics = Graphics.FromImage(NewBitmap)
G.DrawImage(SourceImage, _
New Rectangle(0, 0, SourceImage.Width, SourceImage.Height), 0, 0, _
SourceImage.Width, _
SourceImage.Height, _
GraphicsUnit.Pixel, _
ImgAttr)
End Using
Return NewBitmap
End Function
''' <summary>
''' Diese Funktion ändert die Farbe aller Pixel mit einer bestimmten Farben in einer neuen Farbe
''' </summary>
''' <param name="SourceImage">Das Bild dessen Pixel neu gezeichnet werden sollen</param>
''' <param name="OldColor">Die alte Farbe</param>
''' <param name="NewColor">Die neue Farbe</param>
Public Function PixelRePaint(ByVal SourceImage As Image, ByVal OldColor As Color, ByVal NewColor As Color) As Bitmap
Dim NewBitmap As New Bitmap(SourceImage.Width, SourceImage.Height)
Dim CMap(0) As ColorMap
CMap(0) = New ColorMap
CMap(0).OldColor = OldColor
CMap(0).NewColor = NewColor
Dim ImgAttr As New ImageAttributes
ImgAttr.SetRemapTable(CMap)
Using G As Graphics = Graphics.FromImage(NewBitmap)
G.DrawImage(SourceImage, _
New Rectangle(0, 0, SourceImage.Width, SourceImage.Height), 0, 0, _
SourceImage.Width, _
SourceImage.Height, _
GraphicsUnit.Pixel, _
ImgAttr)
End Using
Return NewBitmap
End Function
Alte URL:
/snippet/alle-pixel-einer-bestimmten-farbe-neu-einfaerben/341
Und so sieht dann das Ergebnis aus wenn man alle weißen Pixel in Schwarze Pixel umwandelt:
Vorher
Nachher
Hier findet man auch echt alles. Echt Klasse was einige Leute so auf die Reihe kriegen ich als Amatuer würd sowas gar nicht hinbekommen. Mach nur weiter so *Thumbsup*.