25-04-14, 05:39 PM
img الصورة
col لون الضوء
opacity النسبة المئوية لمدى شفافية الضوء (رقم من 1 إلى 100)
col لون الضوء
opacity النسبة المئوية لمدى شفافية الضوء (رقم من 1 إلى 100)
كود :
Public Shared Function Light(ByVal img As System.Drawing.Image, ByVal col As System.Drawing.Color, ByVal opacity As Single) As System.Drawing.Image
Dim rectangle As Rectangle
Dim image As New Bitmap(img.Width, img.Height)
Using graphics As Graphics = graphics.FromImage(image)
rectangle = New Rectangle(0, 0, img.Width, img.Height)
graphics.FillRectangle(New SolidBrush(col), rectangle)
End Using
Using graphics2 As Graphics = Graphics.FromImage(img)
Dim imageAttr As New Imaging.ImageAttributes
Dim newColorMatrix As Single()() = New Single()() {New Single() {2.0!, 0.0!, 0.0!, 0.0!, 0.0!}, New Single() {0.0!, 1.0!, 0.0!, 0.0!, 0.0!}, New Single() {0.0!, 0.0!, 1.0!, 0.0!, 0.0!}, New Single() {0.0!, 0.0!, 0.0!, opacity / 100, 0.0!}, New Single() {0.2!, 0.2!, 0.2!, 0.0!, 1.0!}}
Dim matrix As New Imaging.ColorMatrix(newColorMatrix)
imageAttr.SetColorMatrix(matrix, Imaging.ColorMatrixFlag.Default, Imaging.ColorAdjustType.Bitmap)
rectangle = New Rectangle(0, 0, img.Width, img.Height)
graphics2.DrawImage(image, rectangle, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imageAttr)
End Using
Return img
End Function
