تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
التعامل مع الصور Images في بيئة الدوت نت باستخدام +GDI - الجزء العاشر
#1
كاتب الموضوع : 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
ستلاحظ عزيزي القارئ في بالكود أعلاه أننا قد قمنا بتعريف صورة ثالثة وهي يمثلها المتغير fbmp وباستخدام GetThumbnail جعلنا أبعاد الصورة الجديدة تساوي أبعاد الصورة الأصلية ثم قمنا بعرضها في PictureBox وهنا يمكننا الاستغناء عن استخدام GetThumnail وإلغاء هذا السطر من الكود ونقوم بعرض الصورة bmpRef مباشرة داخل PictureBox بدلا من استخدام الصورة fbmp
وكالمعتاد من الممكن إنشاء الكثير من الدوال من المثال أعلاه و مجموعة الأكواد التالية توضح شكل الدوال التي من الممكن بناؤها


كود :
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
ولنعطي مثالا علي استخدام واحدة من الدوال أعلاه ولتنفيذ المثال افتح مشروع وقم بتعريف صورة ثم أضف 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 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

بالتوفيق
أخوكم عمر
}}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  نظرة على DropBox SDK و التعامل معها +برنامج رفع و تحميل ملفات ابو ليلى 4 4,871 08-09-22, 11:54 AM
آخر رد: saif2023
  الجزء الثالث من:كيف تجعل الـ Text Box ذكي!يترجم العمليات الحسابية ويخرج الناتج (الأقواس المتعددة) !! أنس محمود 10 7,827 19-07-22, 12:15 AM
آخر رد: StartLight4000
Video [درس فيديو] تقارير الكريستال ريبورت وتغيير مسار الصور أثناء التشغيل رمضان272 0 1,607 28-03-22, 03:18 AM
آخر رد: رمضان272
  شرح خوارزميات معالجة الصور (من دروس الاستاذ فوزي برزنجي) ناديه الشجيري 19 34,332 20-02-22, 02:13 PM
آخر رد: رضوان الجماعي
  التعامل مع الصور Images في بيئة الدوت نت باستخدام +GDI - مقدمة RaggiTech 3 5,858 30-07-21, 05:14 PM
آخر رد: kebboud
Lightbulb [مقال] التعامل مع ملفات اوفيس من خلال مكتبة NPOI ابو ليلى 2 4,191 01-07-21, 11:42 AM
آخر رد: kebboud
Lightbulb [مقال] التعامل مع اختصارات الملفات Shortcuts Magic Sword 2 4,414 01-10-20, 11:36 AM
آخر رد: abomo3ath
  [مقال] دوال التعامل مع النصوص Strings - VB.NET ابو ليلى 10 25,063 15-04-19, 07:09 PM
آخر رد: alsouf
  Compare Images المقارنة بين الصور Abu Ehab 0 3,269 31-10-18, 04:27 PM
آخر رد: Abu Ehab
  اصنع محرر أكواد خاص بك باستخدام الأداة RichTextBox السكر المغرور 13 7,504 19-08-18, 09:27 AM
آخر رد: elgokr

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم