473,549 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ImageList indexer returns Copy of Image instead of Reference

We're using a System.Windows. Forms.ImageList to store a bunch of Images that
I've loaded, and rendering each image in the ImageList during a draw loop.
The process was running unusually slow and was causing memory spikes. After
several hours we discovered that the ImageList.Image s indexer is actually
returning a copy of the added Images instead of simply returning a reference.
Needless to say, we were a bit surprised and disturbed to discover this.

1) Can anyone answer why the ImageList collection returns a copy instead of
a reference?

2) Is there a way to get the reference instead of a copy?

If you run the example code below, the output to the console window will be
"Different Image".

// Example Code

System.Windows. Forms.ImageList imageList =
new System.Windows. Forms.ImageList ();

System.Drawing. Image image =
System.Drawing. Image.FromFile( @"C:\image.png" );

imageList.Image s.Add(image);

// Get the same Image twice!
System.Drawing. Image imageFromList1 = imageList.Image s[0];
System.Drawing. Image imageFromList2 = imageList.Image s[0];

if (object.Referen ceEquals(imageF romList1, imageFromList2) )
{
Console.WriteLi ne("Same Image");
}
else
{
Console.WriteLi ne("Different Image");
}

Console.ReadLin e();
Feb 21 '08 #1
2 3546
Can you give more info on the setup? For example, would it be possible
to simply switch to a "List<Image >"? or are you using the ImageList to
supply other controls?
Feb 21 '08 #2
We're using a third party framework that is rendering the Image.
Unfortunately, it requires the use of an ImageList, and an index into the
ImageList. We currently have worked around the problem by not using this
feature of the third party framework (using the List<Imagelike you
suggested), but it's not an ideal solution.

Thanks!

"Marc Gravell" wrote:
Can you give more info on the setup? For example, would it be possible
to simply switch to a "List<Image >"? or are you using the ImageList to
supply other controls?
Feb 21 '08 #3

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

Similar topics

14
8346
by: Nikhil Patel | last post by:
Hi all, Is it possible to have more than one indexer in a class. If not, are there any good alternative ways to achieve similar functionality. Thanks... -Nikhil
1
1635
by: Iulian Ionescu | last post by:
I have the following problem. I derived a class from ArrayList to provide some additional events I need. Then I derived 2 different classes from this one and each of them defines an indexer that returns the specified object. For example, the list for Group types will have: public new Group this { get {return (Group)base;}
2
8509
by: Sanjeeva Reddy | last post by:
hai Anti Keskinen, i have used the following code MyListView->LargeImageList->ImageSize = gcnew System::Drawing::Size(100, 100); // Sets large image size to 100, 100 here i am getting error like "gcnew is undeclared error",how to deeclare 'gcnew" and when i am using in runtime to change the size of images in imagelist in listview control...
16
2259
by: Roger | last post by:
....or am I missing something? Setup: - I've created an empty Winforms project, and added two buttons A and B. - Button A's Image property is set to point to a imagefile calles "users.png" - Added an imagelist and added the SAME image to this list, setting the properties (size etc.) exactly the same as for A's Image property. - Set...
0
2828
by: Andre Viens | last post by:
Hello, I am using the following variation of code from <http://support.microsoft.com/default.aspx?scid=kb;EN-US;319340> to add icons to an imagelist for use in a listview: Private Structure SHFILEINFO Public hIcon As IntPtr ' : icon Public iIcon As Integer ' : icondex Public dwAttributes As Integer ' : SFGAO_ flags
1
1966
by: Peter Larsen | last post by:
Hi, How do i copy the images from handle to an instance of ImageList ?? This is what i have : Win32Ass.SHFILEINFO shinfo = new Win32Ass.SHFILEINFO(); IntPtr hImgSmall; //the handle to the system image list hImgSmall = Win32Ass.SHGetFileInfo("c:\\", 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32Ass.SHGFI_SYSICONINDEX |
1
8002
by: Kristopher Wragg | last post by:
Hi, I'm creating a customized picturebox that will have an array of images and some properties that will allow the picturebox to change its image to one of the images in the array depending on events that it registers for... I'm having trouble storing an array of images though, I've tried Image but this doesn't work correctly, I've...
2
4843
by: senfo | last post by:
I'm using a ListView control to display pictures similarly to how Windows Explorer displays pictures in "Thumbnails" view. The images are stored in an ImageList component. I would like to provide the ability to rotate the images and I'm having some issues. Basically, what I've tried is: ...
0
1215
by: wolffy | last post by:
okay heres my problem; i want to add image K to a imagelist, thats easy. The hard part is that the imagelist was made in Application Settings. **I made the imagelist in application settings so i could eventually add in code which would make its value saved when the form closes** But every time i use something like this image k =...
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7715
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7469
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.