改變不透明度我使用此功能在圖片框
Public Shared Function ChangeOpacity(ByVal img As Image, ByVal opacityvalue As Single) As Bitmap
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
我使用這個命令
picturebox.Image = ChangeOpacity(picturebox.Image,0.3)
這是工作,圖片框的不透明度是消退。 但是當我嘗試這個
picturebox.Image = ChangeOpacity(picturebox.Image,1.0)
它沒有發生,畫面依然淡出我要回圖片到默認 如何解決這一問題? 非常感謝您
它的工作原理!謝謝 ! – user3709879
當您更改圖片框中的圖像時,您需要確保在舊圖像上調用「Dispose」! –
@CodyGray現在檢查它的先生。這是正確的? – Sathish