Home All Groups Group Topic Archive Search About
Author
3 Apr 2005 4:08 PM
Fabio Cannizzo via .NET 247
The TreeNode of my TreeView have a property that identify if the node as active or inactive.

I would like the Image associated with the particular inactive nodes to appear greyed.

My idea was to load two copies of each image in the ImageList, one normal and one greyed, but I do not know how to create a greyed bitmap from a normal bitmap.

Can anybody help?

Thanks,
Fabio


--------------------------------
From: Fabio Cannizzo

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>mrZ/xopcxUu3fgTyzlLSiw==</Id>

Author
3 Apr 2005 5:21 PM
Frank Eller
Hi Fabio,

> I do not know how to create a greyed
> bitmap from a normal bitmap.

Use:
Photoshop
Corel Photopaint
PaintShop Pro
....
any Graphics program can do it.

You can of course also use .NET :

using System;
using System.Drawing;
using System.Drawing.Imaging;

....

public static Bitmap CreateGrayscaledBitmap( Image image )
{
   // Create new Bitmap with size of the original bitmap
   Bitmap bitmap = new Bitmap( image.Width, image.Height );

   // create a matrix to convert the colors
   ColorMatrix colorMatrix = new ColorMatrix( new float[][] {
      new float[] {0.3F, 0.3F, 0.3F, 0, 0},
      new float[] {0.59F, 0.59F, 0.59F, 0, 0},
      new float[] {0.11F, 0.11F, 0.11F, 0, 0},
      new float[] {0, 0, 0, 1, 0},
      new float[] {0, 0, 0, 0, 1}
   } );

   ImageAttributes imageAttributes = new ImageAttributes();
   imageAttributes.SetColorMatrix( colorMatrix );
   Graphics g = Graphics.FromImage( bitmap );
   g.DrawImage( image, new Rectangle( 0, 0, image.Width, image.Height ),
      0, 0, image.Width, image.Height, GraphicsUnit.Pixel,
      imageAttributes );
   g.Dispose();

   return bitmap;
}

Regards,

Frank Eller
www.frankeller.de
Are all your drivers up to date? click for free checkup

Author
3 Apr 2005 5:42 PM
Tim Wilson
As an alternative to using a ColorMatrix, you could also use the static
DrawImageDisabled method of the ControlPaint class.

--
Tim Wilson
..Net Compact Framework MVP

Show quoteHide quote
"Frank Eller" <fe[NOSPAM]@frankeller.de> wrote in message
news:ujayHGHOFHA.3076@TK2MSFTNGP14.phx.gbl...
> Hi Fabio,
>
> > I do not know how to create a greyed
> > bitmap from a normal bitmap.
>
> Use:
> Photoshop
> Corel Photopaint
> PaintShop Pro
> ...
> any Graphics program can do it.
>
> You can of course also use .NET :
>
> using System;
> using System.Drawing;
> using System.Drawing.Imaging;
>
> ...
>
> public static Bitmap CreateGrayscaledBitmap( Image image )
> {
>    // Create new Bitmap with size of the original bitmap
>    Bitmap bitmap = new Bitmap( image.Width, image.Height );
>
>    // create a matrix to convert the colors
>    ColorMatrix colorMatrix = new ColorMatrix( new float[][] {
>       new float[] {0.3F, 0.3F, 0.3F, 0, 0},
>       new float[] {0.59F, 0.59F, 0.59F, 0, 0},
>       new float[] {0.11F, 0.11F, 0.11F, 0, 0},
>       new float[] {0, 0, 0, 1, 0},
>       new float[] {0, 0, 0, 0, 1}
>    } );
>
>    ImageAttributes imageAttributes = new ImageAttributes();
>    imageAttributes.SetColorMatrix( colorMatrix );
>    Graphics g = Graphics.FromImage( bitmap );
>    g.DrawImage( image, new Rectangle( 0, 0, image.Width, image.Height ),
>       0, 0, image.Width, image.Height, GraphicsUnit.Pixel,
>       imageAttributes );
>    g.Dispose();
>
>    return bitmap;
> }
>
> Regards,
>
> Frank Eller
> www.frankeller.de
>
>
>

Bookmark and Share