473,320 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Grey images in TreeView

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>
Nov 17 '05 #1
2 2606
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

Nov 17 '05 #2
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

"Frank Eller" <fe[NOSPAM]@frankeller.de> wrote in message
news:uj**************@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

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bryan | last post by:
I have a TreeView, with an ImageList. The ImageList's size is set to 20x15, and all of the images it contains are 20x15. When I use it with the TreeView, though, all of the images are scaled to...
1
by: Abdessamad Belangour | last post by:
Hi all, I have a Windows Form class containing a treeView control. I have another class HierarchyDocument that creates a hierarchy of treeNodes and has a method (createHierarchy) that returns...
2
by: John Bowman | last post by:
Hello, I'm tyring to understand something about using a TreeView ctrl & assigning the images. For testing purposes I'm just using the VS IDE to create and assign the contents of the TreeView....
3
by: Grant Schenck | last post by:
Hello, I'm going round and round on how to best handle images for a treeview control. These are all known at design time so there is no dynamic aspect. That said, I want to associate the...
2
by: Jurjen de Groot | last post by:
The IE webControls come with standard graphics for the treeview amongst other things, does anyone know of other sets of images so the treeview doesn't look so much like the Windows Explorer tree...
1
by: Shane | last post by:
Is there a way to change the HideSelection color in a treeview? I'm using the treeview as a replacement of a tab control. The grey background doesn't stand out well enough, when the treeview loses...
0
by: SBelzile | last post by:
Hi, We are working on a vb.net WinForms project based on the Composite UI Application Block (VS2005). I have a strange problem. At first, I thought 10 minutes would be fairly enough for me to...
1
by: Jeffrey Walton | last post by:
Hi All, I have an array of 16x16 bitmaps (60 total). I've tried adding the array to the ImageList with the Add method, but the TreeView paints as if no BMP is present. The problem is the...
1
by: =?Utf-8?B?TWFya3VzIFNjaC4=?= | last post by:
Hello, i'm seeking for a Favorites and Shortcut image for a TreeView Control. (The Shortcut image should be combined with the object image with DrawImageUnscaled) They should look like in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.