473,395 Members | 1,653 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.

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.Images 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.Images.Add(image);

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

if (object.ReferenceEquals(imageFromList1, imageFromList2))
{
Console.WriteLine("Same Image");
}
else
{
Console.WriteLine("Different Image");
}

Console.ReadLine();
Feb 21 '08 #1
2 3528
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
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
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...
2
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...
16
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" -...
0
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...
1
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...
1
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...
2
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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,...
0
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...
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
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...

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.