Hallo zusammen,
habe mich heute noch einmal mit meinem Programm befasst.
Da ich leider die Lockbit - Möglichkeit für mein Problem nicht richtig umsetzen kann (Verständnisprobleme), habe ich folgende Möglichkeit gefunden.
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Public Class Form5
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
OpenFileDialog1.Filter = "JPG (*.JPG)|*.jpg|GIF (*.gif)|*.gif|Alle|*.*"
OpenFileDialog1.ShowDialog()
BildAnzeigeNeu.Image = Image.FromFile(OpenFileDialog1.FileName)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button2.Click
PictureBox1.Image = BildAnzeigeNeu.Image
PictureBox1.Refresh()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
If IsNothing(BildAnzeigeNeu.Image) Then Exit Sub
Dim Diff As Byte = Farbabweichung.Text
Dim A As Byte = AktuelleFarbeA.Text
Dim R As Byte = AktuelleFarbeR.Text
Dim G As Byte = AktuelleFarbeG.Text
Dim B As Byte = AktuelleFarbeB.Text
Dim RN As Byte
Dim GN As Byte
Dim BN As Byte
Dim z As Integer
For z = Diff * -1 To Diff
Dim bmp As Bitmap = New Bitmap(BildAnzeigeNeu.Image)
Dim Graph As Graphics = Graphics.FromImage(bmp)
RN = R + z
GN = G + z
BN = B + z
If RN < 0 Then
RN = 0
End If
If RN > 255 Then
RN = 255
End If
If GN < 0 Then
GN = 0
End If
If GN > 255 Then
GN = 255
End If
If BN < 0 Then
BN = 0
End If
If BN > 255 Then
BN = 255
End If
Dim attr As New ImageAttributes
Dim c As Color = Color.FromArgb(0, RN, GN, BN)
' Set the transparency color key based on the upper-left pixel
' of the image.
' Uncomment the following line to make all black pixels transparent:
' attr.SetColorKey(bmp.GetPixel(0, 0), bmp.GetPixel(0, 0))
' Set the transparency color key based on a specified value.
' Uncomment the following line to make all red pixels transparent:
attr.SetColorKey(c, c)
' Draw the image using the image attributes.
PictureBox1.Image = Nothing
Dim dstRect As New Rectangle(0, 0, bmp.Width, bmp.Height)
e.Graphics.DrawImage(bmp, dstRect, 0, 0, bmp.Width, bmp.Height, _
GraphicsUnit.Pixel, attr)
Next
End Sub
Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
AktuelleFarbeA.Text = 255
AktuelleFarbeR.Text = 220
AktuelleFarbeG.Text = 241
AktuelleFarbeB.Text = 236
Farbabweichung.Text = 0
'invert()
End Sub
end class So wie der Code oben angeben ist, wird die eingestellte Farbe auch super schnell in Transparent geändert.
Sobald aber die Farbabweichung >0 ist, tut sich optisch nichts. Das Programm bleibt bei der Zeile
Dim bmp As Bitmap = New Bitmap(BildAnzeigeNeu.Image)
hängen. Fehlermeldung: Nicht genügend Arbeitsspeicher
Wenn die Schleife einmal durchgelaufen ist, müsste ich doch eigentlich 'nur' das geänderte Bild abspeichern und dieses erneut durchlaufen lassen, oder?
Wenn ja, wie funktioniert dies bzw. was mache ich falsch.
Für ein Code-Bsp. wäre ich Euch sehr dankbar.
Vielen Dank
Volker
Also liegt die Vermutung nahe, dass diese Funktion nur einmal durchlaufen werden kann |