02-10-12, 03:25 PM
كاتب الموضوع : silverlight
التعامل مع الصور Images في بيئة الدوت نت باستخدام +GDI اللغة المستخدمة: الفيجوال بيسك
التطبيق: فيجوال استوديو 2005 و 2008
المستوي: التقييم متروك للقارئ
إعداد: مهندس / عمر أمين إبراهيم
الجزء العاشر: رسم انعكاس للصورة ٌImage Reflection
يمكن تلخيص عملية رسم إنعاس للصورة في الخطوات التالية
يتم أولا تعريف الصورة الأصلية ثم نقوم بتعريف صورة جديدة أخري بحيث يكون عرض الصورة الجديدة مساويا لعرض الصورة الأصلية و ارتفاع الصورة الجديدة يكون مساويا لارتفاع الصورة الأصلية بالإضافة الي ارتفاع إضافي أخر وهو الي سنرسم به الصورة الأصلية بشكل معكوس وهنا المقصود أننا سنقسم الصورة الجديدة الي مستطيلان مستطيل يمثل الجزء العلوي من الصورة الجديدة ومستطيل أخر يمثل الجزء الأسفل من الصورة الجديدة ثم نقوم برسم الصورة الأصلية بأبعادها الفعلية وبدون تغيير أي من صفاتها في الجزء العلوي من الصورة الجديدة ثم نقوم بعمل دوران للصورة الأصلية وذلك لعكس اتجاها ثم مرة أخري نقوم برسم الصورة الأصلية بعد أن نكون قد عكسنا اتجاهها في منطقة الارتفاع الإضافي من الصورة الجديدة كما يمكننا أيضا أن نرسم أي مؤثرات نريدها طبقا لرغبتنا وفي المثال التالي علي سبيل المثال قمت بتغطية الجزء المعكوس من الصورة بلون شفاف
ولنعطي مثالا علي ذلك
لتنفيذ المثال افتح مشروع جديد وقم بتعريف صورة ثم أضف الي الفورم PictureBox ثم اكتب الكود بالشكل التالي
كود :
Public Class Form1
Dim bmp As New Bitmap(My.Resources.baby_5)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim scale As Single = 0.75
Dim rh As Integer = bmp.Height * scale
Dim ImageHeight As Integer = CInt(bmp.Height + rh)
Dim bmpRef As New Bitmap(bmp.Width, ImageHeight, bmp.PixelFormat)
bmpRef.SetResolution(bmp.HorizontalResolution, bmp.VerticalResolution)
Dim Clr As Color = Color.FromArgb(100, bmp.GetPixel(0, 0))
Dim rectOrig As New Rectangle(0, 0, bmp.Width, bmp.Height)
Dim rectRef As New Rectangle(0, bmp.Height, bmp.Width, rh)
Dim g As Graphics = Graphics.FromImage(bmpRef)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bmp, New Point(0, 0))
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY)
g.DrawImage(bmp, rectRef)
Dim lgb As New System.Drawing.Drawing2D.LinearGradientBrush(rectRef, Color.FromArgb(150, Clr), Clr, 90, True)
g.FillRectangle(lgb, rectRef)
Dim fbmp As Bitmap = bmpRef.GetThumbnailImage(bmp.Width, bmp.Height, Nothing, Nothing)
PictureBox1.Image = fbmp
PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage
End Sub
End Class
وكالمعتاد من الممكن إنشاء الكثير من الدوال من المثال أعلاه و مجموعة الأكواد التالية توضح شكل الدوال التي من الممكن بناؤها
كود :
Public Shared Function ImageReflect(ByVal bitmap As Bitmap) As Bitmap
Dim Clr As Color = Color.FromArgb(100, bitmap.GetPixel(0, 0))
Dim scale As Single = 0.75
Dim rh As Integer = bitmap.Height * scale
Dim ImageHeight As Integer = CInt(bitmap.Height + rh)
Dim bmpRef As New Bitmap(bitmap.Width, ImageHeight, bitmap.PixelFormat)
Dim rectOrig As New Rectangle(0, 0, bitmap.Width, bitmap.Height)
Dim rectRef As New Rectangle(0, bitmap.Height, bitmap.Width, rh)
bmpRef.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution)
Dim g As Graphics = Graphics.FromImage(bmpRef)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bitmap, New Point(0, 0))
bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY)
g.DrawImage(bitmap, rectRef)
Dim lgb As New System.Drawing.Drawing2D.LinearGradientBrush(rectRef, Color.FromArgb(150, Clr), Clr, 90, True)
g.FillRectangle(lgb, rectRef)
Dim bmp As Bitmap = bmpRef.GetThumbnailImage(bitmap.Width, bitmap.Height, Nothing, Nothing)
Return bmp
End Function
Public Shared Function ImageReflect(ByVal bitmap As Bitmap, ByVal Scale As Single) As Bitmap
If Scale < 0.3 OrElse Scale > 1 Then
Throw New ArgumentOutOfRangeException("Scale must be between 0.3 and 1.")
End If
Dim Clr As Color = Color.FromArgb(100, bitmap.GetPixel(0, 0))
Dim rh As Integer = bitmap.Height * Scale
Dim ImageHeight As Integer = CInt(bitmap.Height + rh)
Dim bmpRef As New Bitmap(bitmap.Width, ImageHeight, bitmap.PixelFormat)
Dim rectOrig As New Rectangle(0, 0, bitmap.Width, bitmap.Height)
Dim rectRef As New Rectangle(0, bitmap.Height, bitmap.Width, rh)
bmpRef.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution)
Dim g As Graphics = Graphics.FromImage(bmpRef)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bitmap, New Point(0, 0))
bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY)
g.DrawImage(bitmap, rectRef)
Dim lgb As New System.Drawing.Drawing2D.LinearGradientBrush(rectRef, Color.FromArgb(150, Clr), Clr, 90, True)
g.FillRectangle(lgb, rectRef)
Dim bmp As Bitmap = bmpRef.GetThumbnailImage(bitmap.Width, bitmap.Height, Nothing, Nothing)
Return bmp
End Function
Public Shared Function ImageReflect(ByVal bitmap As Bitmap, ByVal Scale As Single, ByVal color As Color) As Bitmap
If Scale < 0.3 OrElse Scale > 1 Then
Throw New ArgumentOutOfRangeException("Scale must be between 0.3 and 1.")
End If
Dim Clr As Color = color.FromArgb(100, color)
Dim rh As Integer = bitmap.Height * Scale
Dim ImageHeight As Integer = CInt(bitmap.Height + rh)
Dim bmpRef As New Bitmap(bitmap.Width, ImageHeight, bitmap.PixelFormat)
Dim rectOrig As New Rectangle(0, 0, bitmap.Width, bitmap.Height)
Dim rectRef As New Rectangle(0, bitmap.Height, bitmap.Width, rh)
bmpRef.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution)
Dim g As Graphics = Graphics.FromImage(bmpRef)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bitmap, New Point(0, 0))
bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY)
g.DrawImage(bitmap, rectRef)
Dim lgb As New System.Drawing.Drawing2D.LinearGradientBrush(rectRef, Color.FromArgb(150, Clr), Clr, 90, True)
g.FillRectangle(lgb, rectRef)
Dim bmp As Bitmap = bmpRef.GetThumbnailImage(bitmap.Width, bitmap.Height, Nothing, Nothing)
Return bmp
End Function
Public Shared Function ImageReflect(ByVal bitmap As Bitmap, ByVal Scale As Single, ByVal color As Color, ByVal ReflectionHeight As Integer) As Bitmap
If Scale < 0.3 OrElse Scale > 1 Then
Throw New ArgumentOutOfRangeException("Scale must be between 0.3 and 1.")
End If
If ReflectionHeight > bitmap.Height Then
Throw New ArgumentOutOfRangeException("Reflection Height must be less than bitmap height.")
End If
Dim Clr As Color = color.FromArgb(100, color)
Dim rh As Integer = ReflectionHeight * Scale
Dim ImageHeight As Integer = CInt(bitmap.Height + rh)
Dim bmpRef As New Bitmap(bitmap.Width, ImageHeight, bitmap.PixelFormat)
Dim rectOrig As New Rectangle(0, 0, bitmap.Width, bitmap.Height)
Dim rectRef As New Rectangle(0, bitmap.Height, bitmap.Width, rh)
bmpRef.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution)
Dim g As Graphics = Graphics.FromImage(bmpRef)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bitmap, New Point(0, 0))
bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY)
g.DrawImage(bitmap, rectRef)
Dim lgb As New System.Drawing.Drawing2D.LinearGradientBrush(rectRef, color.FromArgb(150, Clr), Clr, 90, True)
g.FillRectangle(lgb, rectRef)
Dim bmp As Bitmap = bmpRef.GetThumbnailImage(bitmap.Width, bitmap.Height, Nothing, Nothing)
Return bmp
End Function
كود :
Public Class Form1
Dim bmp As New Bitmap(My.Resources.baby_5)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim bmpHeight As Integer = bmp.Height
PictureBox1.Image = ImageReflect(bmp, 0.7, Color.Aqua, bmpHeight * 0.8)
PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage
End Sub
Public Shared Function ImageReflect(ByVal bitmap As Bitmap, ByVal Scale As Single, ByVal color As Color, ByVal ReflectionHeight As Integer) As Bitmap
If Scale < 0.3 OrElse Scale > 1 Then
Throw New ArgumentOutOfRangeException("Scale must be between 0.3 and 1.")
End If
If ReflectionHeight > bitmap.Height Then
Throw New ArgumentOutOfRangeException("Reflection Height must be less than bitmap height.")
End If
Dim Clr As Color = color.FromArgb(100, color)
Dim rh As Integer = ReflectionHeight * Scale
Dim ImageHeight As Integer = CInt(bitmap.Height + rh)
Dim bmpRef As New Bitmap(bitmap.Width, ImageHeight, bitmap.PixelFormat)
Dim rectOrig As New Rectangle(0, 0, bitmap.Width, bitmap.Height)
Dim rectRef As New Rectangle(0, bitmap.Height, bitmap.Width, rh)
bmpRef.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution)
Dim g As Graphics = Graphics.FromImage(bmpRef)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bitmap, New Point(0, 0))
bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY)
g.DrawImage(bitmap, rectRef)
Dim lgb As New System.Drawing.Drawing2D.LinearGradientBrush(rectRef, color.FromArgb(150, Clr), Clr, 90, True)
g.FillRectangle(lgb, rectRef)
Dim bmp As Bitmap = bmpRef.GetThumbnailImage(bitmap.Width, bitmap.Height, Nothing, Nothing)
Return bmp
End Function
End Class
بالتوفيق
أخوكم عمر