|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Grey images in TreeViewI 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> Hi Fabio,
> I do not know how to create a greyed Use:> bitmap from a normal bitmap. 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 As an alternative to using a ColorMatrix, you could also use the static
DrawImageDisabled method of the ControlPaint class. -- Show quoteHide quoteTim Wilson ..Net Compact Framework MVP "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 > > > |
|||||||||||||||||||||||