472,374 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 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 4726
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: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.