Neuer Tag - Neues Problem
Ich habe einen Code der momentan ganz gut klappt und den Inhalt eines Panels als ein Bild (.PNG) abspeichert.
Mein Problem ist, dass obwohl die BackgroundColor des Panels auf "Transparent" eingestellt ist, die Backgroundcolor der Form als Hintergrund des Bilded gespeichert wird.
Habt ihr eine Idee wie ich das Panel so abspeichern kann, dass das .PNG Bild einen transparenten Hintergrund hat?
Vielen vielen Dank
Code:
Ich habe einen Code der momentan ganz gut klappt und den Inhalt eines Panels als ein Bild (.PNG) abspeichert.
Mein Problem ist, dass obwohl die BackgroundColor des Panels auf "Transparent" eingestellt ist, die Backgroundcolor der Form als Hintergrund des Bilded gespeichert wird.
Habt ihr eine Idee wie ich das Panel so abspeichern kann, dass das .PNG Bild einen transparenten Hintergrund hat?
Vielen vielen Dank
Code:
VB.NET-Quellcode
-
- <DllImport("gdi32.dll")> _
- Private Shared Function BitBlt(ByVal hdc As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As Integer) As Boolean
- End Function
- Function GetImageFromControl(ByVal ctr As Control) As Image
- Dim rect As Rectangle = ctr.ClientRectangle
- Dim bmp As New Bitmap(rect.Width, rect.Height)
- Dim gbmp As Graphics = Graphics.FromImage(bmp)
- Dim hdcBmp As IntPtr = gbmp.GetHdc
- Dim gMe As Graphics = ctr.CreateGraphics
- Dim hdcMe As IntPtr = gMe.GetHdc
- BitBlt(hdcBmp, 0, 0, rect.Width, rect.Height, hdcMe, 0, 0, &HCC0020)
- gbmp.ReleaseHdc(hdcBmp)
- gMe.ReleaseHdc(hdcMe)
- Return bmp
- End Function
- Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
- GetImageFromControl(Panel1).Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.png"))
- End Sub