Ich habe einen Bildschirmschoner, der ein 768x250 Pixel großes Bild auf zwei verschiedenen Monitoren immer ein- und ausblendet. Für die Änderung der Deckkraft benutze ich folgende Funktion:
Während dieses Fade-Effekts geht der RAM-verbrauch auf über 1 GB hoch. Kann man das irgendwie optimieren? Die Originalgrafik in der PictureBox ist ein 32Bit-PNG.
VB.NET-Quellcode
- Public Function ChangeOpacity(ByVal img As Image, ByVal opacityvalue As Single) As Bitmap
- ' -----------
- ' Deckkraft eines Bildes ändern
- ' -----------
- If opacityvalue > 100 Then
- opacityvalue = 100
- ElseIf opacityvalue < 0 Then
- opacityvalue = 0
- End If
- Dim bmp As New Bitmap(img.Width, img.Height)
- Dim graphics__1 As Graphics = Graphics.FromImage(bmp)
- Dim colormatrix As New colormatrix
- colormatrix.Matrix33 = opacityvalue
- Dim imgAttribute As New ImageAttributes
- imgAttribute.SetColorMatrix(colormatrix, ColorMatrixFlag.[Default], ColorAdjustType.Bitmap)
- graphics__1.DrawImage(img, New Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttribute)
- graphics__1.Dispose()
- Return bmp
- End Function
Während dieses Fade-Effekts geht der RAM-verbrauch auf über 1 GB hoch. Kann man das irgendwie optimieren? Die Originalgrafik in der PictureBox ist ein 32Bit-PNG.