Hallo,
vielleicht wäre es dabei doch geschickter, jedes in eine einzelne PictureBox zu legen und die Region anzupassen...dafür hab ich glaub sogar noch code...ich such dann mal^^
Edit: gefunden...
Public Function GetColors(ByVal bmp As Bitmap) As PfadList
Dim rect As New Rectangle(0, 0, bmp.Width, bmp.Height)
Dim bd As Imaging.BitmapData = bmp.LockBits(rect, _
Imaging.ImageLockMode.ReadOnly, _
Imaging.PixelFormat.Format32bppArgb)
Dim byt As Int32 = (bd.Stride * bmp.Height) - 1
Dim col(byt) As Byte
Runtime.InteropServices.Marshal.Copy(bd.Scan0, col, 0, byt)
bmp.UnlockBits(bd)
Dim lst As New PfadList
For y As Int32 = 0 To bmp.Height - 1
For x As Int32 = 0 To bd.Stride - 4 Step 4
Dim item As New Pfad
item.X = x / 4
item.Y = y
item.Farbe = Color.FromArgb(col(x + y * bd.Stride + 3), col(x + _
y * bd.Stride + 2), col(x + y * bd.Stride + 1), col(x + y * _
bd.Stride))
lst.Add(item)
Next
Next
Return lst
End Function
Function ToRegion(ByVal Bitmap As Bitmap, ByVal TransparentColor As Color) _
As Region
Dim pth As PfadList = GetColors(Bitmap)
Dim pf As New Drawing2D.GraphicsPath
For i As Integer = 0 To pth.List.Count - 1
If pth.List(i).Farbe.A <> TransparentColor.A Or pth.List( _
i).Farbe.R <> TransparentColor.R Or pth.List(i).Farbe.G <> _
TransparentColor.G Or pth.List(i).Farbe.B <> TransparentColor.B Then
pf.AddRectangle(New RectangleF(pth.List(i).X, pth.List(i).Y, 1, _
1))
End If
Next
Return New Region(pf)
End Function
Public Class Pfad
Private m_Farbe As Color
Private m_X As Integer
Private m_Y As Integer
Property X() As Integer
Get
Return m_X
End Get
Set(ByVal value As Integer)
m_X = value
End Set
End Property
Property Y() As Integer
Get
Return m_Y
End Get
Set(ByVal value As Integer)
m_Y = value
End Set
End Property
Property Farbe() As Color
Get
Return m_Farbe
End Get
Set(ByVal value As Color)
m_Farbe = value
End Set
End Property
End Class
Public Class PfadList
Private m_List As New List(Of Pfad)
Property List() As List(Of Pfad)
Get
Return m_List
End Get
Set(ByVal value As List(Of Pfad))
m_List = value
End Set
End Property
Sub Add(ByVal Item As Pfad)
m_List.Add(Item)
End Sub
Function GetColor(ByVal X As Integer, ByVal Y As Integer) As Color
For i As Integer = X * Y To m_List.Count - 1
If m_List(i).X = X And m_List(i).Y = Y Then
Return m_List(i).Farbe
Exit For
End If
Next
End Function
End Class und dann einfach:
PictureBox1.Region = ToRegion(New Bitmap("C:\Deinbild.bmp"),Color.Magenta)
PictureBox1.Image = New Bitmap("C:\Deinbild.bmp") Gruß Julian13
Beitrag wurde zuletzt am 23.10.08 um 15:29:45 editiert. |