"Sugan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
>
> I'm creating a custom button control. I need to show a color image when
> the button control is enabled and a gray shade of the same image when
> the button control is disabled. How can i convert a color image to a
> gray image in VB 2005.
>
> Thanks,
> Sugan
> Chennai, INDIA
Try this:
Private Function Convert2Greyscale(ByVal BitmapIn As System.Drawing.Bitmap)
As System.Drawing.Bitmap
Dim newB As Bitmap = CType(BitmapIn.Clone(), Bitmap)
Dim bounds As System.Drawing.Rectangle = New System.Drawing.Rectangle(0,
0, newB.Width, newB.Height)
Dim clrMatrix As System.Drawing.Imaging.ColorMatrix = New
System.Drawing.Imaging.ColorMatrix
Dim mX, mY As Integer
For mX = 0 To 2
For mY = 0 To 2
clrMatrix(mX, mY) = 0.333333
Next
Next
Dim imgAttr As System.Drawing.Imaging.ImageAttributes = New
System.Drawing.Imaging.ImageAttributes
imgAttr.SetColorMatrix(clrMatrix)
Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(newB)
g.DrawImage(newB, bounds, 0, 0, newB.Width, newB.Height,
System.Drawing.GraphicsUnit.Pixel, imgAttr)
g.Dispose()
Return newB
End Function
HTH
Paul
|