PC Review


Reply
Thread Tools Rate Thread

Convert Color image to Gray Shade Image

 
 
Sugan
Guest
Posts: n/a
 
      5th Jul 2006
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

 
Reply With Quote
 
 
 
 
Paul Larson
Guest
Posts: n/a
 
      5th Jul 2006
"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


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert color image to bi-level image? ShihChengYu@gmail.com Microsoft Dot NET 3 4th Apr 2006 02:22 AM
How to convert color image to bi-level image? ShihChengYu@gmail.com Microsoft C# .NET 0 3rd Apr 2006 02:55 PM
how to get lighter shade of gray for interior color of a cell? =?Utf-8?B?UmljaA==?= Microsoft Excel Programming 8 21st Mar 2006 04:40 AM
Is it possible to convert a 32-bit color image into a 1-bit-per-pixel image in VB.net? If yes, how can it be done? Ira Microsoft VB .NET 2 22nd Feb 2006 01:32 PM
Image - convert color image to black and white programmatically DanS Microsoft Dot NET 2 29th Aug 2003 02:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:41 AM.