473,395 Members | 1,526 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,395 software developers and data experts.

Dynamically loading an Icon into an ImageList from a Stream

I'm having a problem loading an Icon into an ImageList.

When I load the icon directly it works fine, like this:
Icon sourceIcon = << Get an icon from somewhere... >>;
treeViewImageList.Images.Add("abc", sourceIcon);
But when I first save the original icon to a stream and then try loading the
ImageList from the stream, the icon image is messed up. Here's that code:
Icon sourceIcon = << Get an icon from somewhere... >>;
MemoryStream imageStream = new MemoryStream();
sourceIcon.Save(imageStream);
imageStream.Position = 0;
Icon icon = new Icon(imageStream);
treeViewImageList.Images.Add("abc", icon);
The ultimate goal is to use the stream to save the icon byte array to a
database and then load it again later but first I need to be able to get the
icon to reload correctly from the stream.

Any ideas what I'm doing wrong here?

Thanks.

- Adam
Aug 28 '07 #1
1 4866
The following works absolutely fine for me. Are you by any chance
doing something funny with the ImageList.ImageSize? Scaling will make
them look terrible...

Marc

static void Main()
{
Application.EnableVisualStyles();
// tray1 is a random icon in a resx
Icon ico1 = Resource1.tray1, ico2;
using(MemoryStream ms = new MemoryStream()) {
ico1.Save(ms);
ms.Position = 0;
ico2 = new Icon(ms);
}
// show the 2 icons on a treeview
using(Form f = new Form())
using(ImageList il = new ImageList())
using(TreeView tv = new TreeView()) {
il.Images.Add("ico1", ico1);
il.Images.Add("ico2", ico2);
tv.ImageList = il;
tv.Dock = DockStyle.Fill;
tv.Nodes.Add("node1", "Original", "ico1");
tv.Nodes.Add("node2", "Saved", "ico2");
tv.ExpandAll();
f.Controls.Add(tv);
f.ShowDialog();
}
}

Aug 29 '07 #2

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

Similar topics

10
by: Randy Webb | last post by:
This page: http://www.hikksworld.com/loadJSFiles/ Is one where I was testing the ability of browsers that can/can't dynamically load a JS file with one of the three methods: 1)Changing the src...
1
by: Frank Drebin | last post by:
In ASP, I have something like this: Set conn = Server.CreateObject("ADODB.Connection") Set cmd = Server.CreateObject("ADODB.Command") Set adoStream = Server.CreateObject("ADODB.Stream")...
1
by: Benjamin | last post by:
Hi, I'm currently writing a Web Services that interacts with a database. To allow me to use not just one database provider (for example, I could use MS Access, SQL Server or MySQL), the Web...
1
by: José Joye | last post by:
Hello, I'm playing around with dynamically loading user controls ...and having problems I created a really simple userControl (in fact contains a plain text box) and placed it into the...
5
by: footballhead | last post by:
I have a site that has MANY different clothing categories. I have a page set up for displaying the products (productsearch.aspx) when a user clicks one of the category links on the navigation menu....
5
by: Jay Douglas | last post by:
I have a set of pages that inherit from a base class in the App_Code folder. The class looks something like: public class MyBaseClass : System.Web.UI.Page In various stages of the life cycle I...
6
by: Dan Dorey | last post by:
I actually have two questions here, but I'll start by giving an outline of what I'm trying to do. I'm building an app with a simple plugin architecture (all in the same app domain). I have each...
1
by: Bob Rock | last post by:
Hello, I'm new to ASP.NET and I've been looking into the topic of dynamically loading (typically accomplished with a LoadControl followed by a MyControl.Controls.Add()) both user controls and...
20
by: Nickolai Leschov | last post by:
Hello all, I am programming an embedded controller that has a 'C' library for using its system functions (I/O, timers, all the specific devices). The supplied library has .LIB and .H files. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.