تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
التعامل مع الصور Images في بيئة الدوت نت باستخدام +GDI - الجزء الثامن
#4
إذن ومن مجموعة الأكواد السابقة نكتشف أنه يمكننا أن نقوم بتغيير ألوان الصورة الي ما نريد وعلي سبيل المثال يمكننا أن نعكس الألوان أو نجعل الصورة أبيض وأسود أو نجعل ألوان الصورة حمراء الي أخره من التغييرات التي نريدها.
وكالمعتاد من الممكن إنشاء الكثير من الدوال من الأمثلة أعلاه و مجموعة الأكواد التالية توضح شكل الدوال التي من الممكن بناؤها من الكود أعلاه طبعا يمكنك أن تبني أكثر من دالة عزيزي القارئ عموما الأمر متروك لخيالك


كود :
Public Shared Function RevertColor(ByVal color As Color) As Color

Dim clr As Color = color.FromArgb(255, 255 - color.R, 255 - color.G, 255 - color.B)
RevertColor = clr

End Function

Public Shared Function RevertColor(ByVal color As Color, ByVal Alpha As Integer) As Color

If Alpha < 10 OrElse Alpha > 255 Then

Throw New ArgumentOutOfRangeException("Alpha must be between 10 and 255.")
End If

Dim clr As Color = color.FromArgb(255, 255 - color.R, 255 - color.G, 255 - color.B)
RevertColor = clr

End Function

Public Shared Function RevertImageColors(ByVal bitmap As Bitmap) As Bitmap

For x As Integer = 0 To bitmap.Width - 1
For y As Integer = 0 To bitmap.Height - 1

Dim bmpColor As Color = bitmap.GetPixel(x, y)
Dim newclr As Color = Color.FromArgb(bmpColor.G, bmpColor.B, bmpColor.R)
bitmap.SetPixel(x, y, newclr)

Next
Next

Dim bmp As New Bitmap(bitmap.Width, bitmap.Height, bitmap.PixelFormat)
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(bitmap, 0, 0)

Return bmp

End Function

Public Shared Function RevertImageColors(ByVal bitmap As Bitmap, ByVal color As Color) As Bitmap

Dim clr As Color = color.FromArgb(255, color)
For x As Integer = 0 To bitmap.Width - 1
For y As Integer = 0 To bitmap.Height - 1

Dim bmpColor As Color = bitmap.GetPixel(x, y)
Dim newclr As Color = color.FromArgb(clr.R, bmpColor.G, clr.B)
bitmap.SetPixel(x, y, newclr)

Next
Next

Dim bmp As New Bitmap(bitmap.Width, bitmap.Height, bitmap.PixelFormat)
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(bitmap, 0, 0)

Return bmp

End Function

Public Shared Function RevertImageColors(ByVal bitmap As Bitmap, ByVal color As Color, ByVal Alpha As Integer) As Bitmap

If Alpha < 50 OrElse Alpha > 255 Then

Throw New ArgumentOutOfRangeException("Alpha must be between 50 and 255.")
End If


Dim clr As Color = color.FromArgb(Alpha, color)
For x As Integer = 0 To bitmap.Width - 1
For y As Integer = 0 To bitmap.Height - 1

Dim bmpColor As Color = bitmap.GetPixel(x, y)
Dim newclr As Color = color.FromArgb(clr.A, clr.R, bmpColor.G, clr.B)
bitmap.SetPixel(x, y, newclr)

Next
Next

Dim bmp As New Bitmap(bitmap.Width, bitmap.Height, bitmap.PixelFormat)
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(bitmap, 0, 0)

Return bmp

End Function

Public Shared Function TurnImageToGray(ByVal bitmap As Bitmap) As Bitmap

For x As Integer = 0 To bitmap.Width - 1
For y As Integer = 0 To bitmap.Height - 1

Dim bmpColor As Color = bitmap.GetPixel(x, y)
Dim newclr As Color = Color.FromArgb(bmpColor.R, bmpColor.R, bmpColor.R)
bitmap.SetPixel(x, y, newclr)

Next
Next

Dim bmp As New Bitmap(bitmap.Width, bitmap.Height, bitmap.PixelFormat)
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(bitmap, 0, 0)

Return bmp
End Function

Public Shared Function TurnImageToGray(ByVal bitmap As Bitmap, ByVal Transperent As Boolean) As Bitmap

If Transperent Then

For x As Integer = 0 To bitmap.Width - 1
For y As Integer = 0 To bitmap.Height - 1

Dim bmpColor As Color = bitmap.GetPixel(x, y)
Dim newclr As Color = Color.FromArgb(100, bmpColor.R, bmpColor.R, bmpColor.R)
bitmap.SetPixel(x, y, newclr)

Next
Next


Else

For x As Integer = 0 To bitmap.Width - 1
For y As Integer = 0 To bitmap.Height - 1

Dim bmpColor As Color = bitmap.GetPixel(x, y)
Dim newclr As Color = Color.FromArgb(bmpColor.R, bmpColor.R, bmpColor.R)
bitmap.SetPixel(x, y, newclr)

Next
Next
End If


Dim bmp As New Bitmap(bitmap.Width, bitmap.Height, bitmap.PixelFormat)
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(bitmap, 0, 0)

Return bmp
End Function

Public Shared Function TurnImageToMonoChrome(ByVal bitmap As Bitmap) As Bitmap

Dim bmp As New Bitmap(bitmap.Width, bitmap.Height, bitmap.PixelFormat)

For x As Integer = 0 To bmp.Width - 1
For y As Integer = 0 To bmp.Height - 1
Dim bmpColor As Color = bitmap.GetPixel(x, y)
Dim a As Integer = CInt(bmpColor.R * 0.3 + bmpColor.G * 0.59 + bmpColor.B * 0.11)
bmp.SetPixel(x, y, Color.FromArgb(a, a, a))
Next
Next
Return bmp

End Function

Public Shared Function TurnImageToGray(ByVal bitmap As Bitmap, ByVal Transperent As Boolean, ByVal Alpha As Integer) As Bitmap

If Alpha < 50 OrElse Alpha > 255 Then

Throw New ArgumentOutOfRangeException("Alpha must be between 50 and 255.")
End If


If Transperent Then

For x As Integer = 0 To bitmap.Width - 1
For y As Integer = 0 To bitmap.Height - 1

Dim bmpColor As Color = bitmap.GetPixel(x, y)
Dim newclr As Color = Color.FromArgb(Alpha, bmpColor.R, bmpColor.R, bmpColor.R)
bitmap.SetPixel(x, y, newclr)

Next
Next


Else

For x As Integer = 0 To bitmap.Width - 1
For y As Integer = 0 To bitmap.Height - 1

Dim bmpColor As Color = bitmap.GetPixel(x, y)
Dim newclr As Color = Color.FromArgb(bmpColor.R, bmpColor.R, bmpColor.R)
bitmap.SetPixel(x, y, newclr)

Next
Next
End If


Dim bmp As New Bitmap(bitmap.Width, bitmap.Height, bitmap.PixelFormat)
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(bitmap, 0, 0)

Return bmp

End Function
الكود التالي يوضح كيفية استخدام احدي الدوال الموجودة اعلاه وذلك لإعطاء فكرة عن كيفية استخدام هذه الدوال


كود :
Public Class Form1

Dim bmp As New Bitmap(My.Resources.imgsrv)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim bmp1 As Bitmap = TurnImageToGray(bmp, True, 70)
PictureBox1.Image = bmp1
PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage

End Sub

Public Shared Function TurnImageToGray(ByVal bitmap As Bitmap, ByVal Transperent As Boolean, ByVal Alpha As Integer) As Bitmap

If Alpha < 50 OrElse Alpha > 255 Then

Throw New ArgumentOutOfRangeException("Alpha must be between 50 and 255.")
End If

If Transperent Then

For x As Integer = 0 To bitmap.Width - 1
For y As Integer = 0 To bitmap.Height - 1

Dim bmpColor As Color = bitmap.GetPixel(x, y)
Dim newclr As Color = Color.FromArgb(Alpha, bmpColor.R, bmpColor.R, bmpColor.R)
bitmap.SetPixel(x, y, newclr)

Next
Next

Else

For x As Integer = 0 To bitmap.Width - 1
For y As Integer = 0 To bitmap.Height - 1

Dim bmpColor As Color = bitmap.GetPixel(x, y)
Dim newclr As Color = Color.FromArgb(bmpColor.R, bmpColor.R, bmpColor.R)
bitmap.SetPixel(x, y, newclr)

Next
Next
End If
Dim bmp As New Bitmap(bitmap.Width, bitmap.Height, bitmap.PixelFormat)
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(bitmap, 0, 0)
Return bmp
End Function

End Class

بالتوفيق

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


الردود في هذا الموضوع
التعامل مع الصور Images في بيئة الدوت نت باستخدام +GDI - الجزء الثامن - بواسطة Raggi Tech - 02-10-12, 03:23 PM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  نظرة على DropBox SDK و التعامل معها +برنامج رفع و تحميل ملفات ابو ليلى 5 5,975 16-08-24, 04:39 PM
آخر رد: ackore
  الجزء الثالث من:كيف تجعل الـ Text Box ذكي!يترجم العمليات الحسابية ويخرج الناتج (الأقواس المتعددة) !! أنس محمود 10 8,395 19-07-22, 12:15 AM
آخر رد: StartLight4000
Video [درس فيديو] تقارير الكريستال ريبورت وتغيير مسار الصور أثناء التشغيل رمضان272 0 1,999 28-03-22, 03:18 AM
آخر رد: رمضان272
  شرح خوارزميات معالجة الصور (من دروس الاستاذ فوزي برزنجي) ناديه الشجيري 19 35,551 20-02-22, 02:13 PM
آخر رد: رضوان الجماعي
  التعامل مع الصور Images في بيئة الدوت نت باستخدام +GDI - مقدمة RaggiTech 3 6,341 30-07-21, 05:14 PM
آخر رد: kebboud
Lightbulb [مقال] التعامل مع ملفات اوفيس من خلال مكتبة NPOI ابو ليلى 2 4,617 01-07-21, 11:42 AM
آخر رد: kebboud
Lightbulb [مقال] التعامل مع اختصارات الملفات Shortcuts Magic Sword 2 4,707 01-10-20, 11:36 AM
آخر رد: abomo3ath
  [مقال] دوال التعامل مع النصوص Strings - VB.NET ابو ليلى 10 27,160 15-04-19, 07:09 PM
آخر رد: alsouf
  Compare Images المقارنة بين الصور Abu Ehab 0 3,643 31-10-18, 04:27 PM
آخر رد: Abu Ehab
  اصنع محرر أكواد خاص بك باستخدام الأداة RichTextBox السكر المغرور 13 8,186 19-08-18, 09:27 AM
آخر رد: elgokr

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


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