(25-04-14, 03:39 PM)ali.alfoly كتب : السلام عليكم ورحمة الله
عندي صورة داخل PictureBox الصورة لون واحد فقط مثال
اريد مثلا شئ من الجماليات
عند مرور الموس علي الصورة يظهر ضوء علي الصورة بلون معين احمر اصفر اخضر ازرق انا احدد اللون
وجزاكم الله خيرا
مثال على السريع باستغلال PictureBox مع وضع الصور التي في المرفقات في Resources
(مع ملاحظة أن الصورة لا يكون لها هوامش فارغة - لذا قمت بتعديل الصورة التي منك إلى صورة بدون هوامش)
أضف أداة PictureBox
الإعدادت الهامة:
أضف الصورة main.png في BackgroundImage
عدل مقاس الأداء PictureBox إلى نفس مقاس الصورة mail.png وهنا المقاس Size: 48; 34
عدل الخاصية SizeMode إلى StretchImage
كود :
Public Class Form1
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
' حدث النقر
End Sub
#Region "CustomButton"
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Me.PictureBox1.Image = My.Resources.black
End Sub
Private Sub PictureBox1_MouseEnterMouseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseEnter, PictureBox1.MouseUp
Me.PictureBox1.Image = My.Resources.white
End Sub
Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
Me.PictureBox1.Image = Nothing
End Sub
#End Region
img الصورة
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
(26-04-14, 04:14 PM)ali.alfoly كتب : نعم اخي انا فهمت الدالة الي حدرتك طرحتها وهي ممتازة
لاكن طلب الضوء يكون من جهة معينة
كود :
Public Shared Function Light(ByVal img As System.Drawing.Image, ByVal col As System.Drawing.Color, ByVal opacity As Single, Optional ByVal direction As Drawing2D.LinearGradientMode = Drawing2D.LinearGradientMode.ForwardDiagonal) 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)
Dim brush As New Drawing2D.LinearGradientBrush(rectangle, col, Color.Transparent, direction)
graphics.FillRectangle(brush, 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