24-10-13, 06:49 PM
السلام عليكم ورحمة الله وبركاته
تفضل الدالة ImageChannelMixer
طريقة استخدامها
السلام عليكم ورحمة الله وبركاته
تفضل الدالة ImageChannelMixer
كود :
Private Function ImageChannelMixer(ByVal img As Image, ByVal clr As Color) As Image
Dim b1 As New Bitmap(img.Width * 2, img.Height)
Using g1 As Graphics = Graphics.FromImage(b1)
g1.Clear(Color.Transparent)
g1.DrawImage(img, 0, 0, img.Width, img.Height)
End Using
'---------------------------------------
Dim b2 As New Bitmap(b1)
Using g2 As Graphics = Graphics.FromImage(b2)
Dim imageAttributes As New Imaging.ImageAttributes()
Dim colorMatrixElements As Single()() = {New Single() {1, 0, 0, 0, 0}, _
New Single() {0, 1, 0, 0, 0}, _
New Single() {0, 0, 1, 0, 0}, _
New Single() {0, 0, 0, 1, 0}, _
New Single() {(clr.R / 255), (clr.G / 255), (clr.B / 255), 0, 1}}
Dim colorMatrix As New Imaging.ColorMatrix(colorMatrixElements)
imageAttributes.SetColorMatrix(colorMatrix, Imaging.ColorMatrixFlag.Default, Imaging.ColorAdjustType.Default)
g2.DrawImage(b2, New Rectangle(img.Width, 0, b2.Width, b2.Height), _
0, 0, b2.Width, b2.Height, _
GraphicsUnit.Pixel, imageAttributes)
End Using
'---------------------------------------
Dim b3 As New Bitmap(img.Width, img.Height)
Using grp = Graphics.FromImage(b3)
grp.DrawImage(b2, New Rectangle(0, 0, img.Width, img.Height), New Rectangle(img.Width, 0, img.Width, img.Height), GraphicsUnit.Pixel)
End Using
'---------------------------------------
Return b3
End Functionطريقة استخدامها
كود :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PictureBox2.Image = ImageChannelMixer(PictureBox1.Image, Color.Blue)
End Subالسلام عليكم ورحمة الله وبركاته
