473,856 Members | 1,755 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 3570
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
8378
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
1646
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
8542
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 in .net(forms application) by chnging one trckbar(like tb1->Value),
16
2296
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 button B's ImageList property to the new imagelist created, and it's
0
2879
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
2117
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
8026
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 tried
2
4864
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: lstViewImages.LargeImageList.Images.RotateFlip(RotateFlipType.Rotate90FlipNone); lstViewImages.Update();
0
1237
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 = toolstrip1.backgroundimage; Settings.Default.kill.Images.Add(k); **kill is the name of the imagelist** i get...
0
9916
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9762
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11056
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10384
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9531
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7093
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4575
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
2
4174
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3201
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.