I'm trying to draw PNG images in the OnPaint event of a usercontrol I created.
The files are loaded from disk into an ArrayList using Image.FromFile.
I get very unexpected results, sometimes loading the ArrayList produces an error, other times the application crashes in the OnPaint event. The files are quite small: 5MB at the most, in total no more than 50MB is loaded. The error is always OutOfMemoryException.
When I convert the PNG's beforehand to Bitmaps, the size of course increases dramatically, to several hundred MB. This however works brilliantly, no errors and even acceptable performance. But I can't the bitmaps because I need the transparency of the PNG format. And for other reasons too I have to use the PNG's.
What's wrong with PNG and GDI+?
Any pointers appreciated.
VB.NET, Visual Studio 2005, .NET 2.0
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
If Not mImageList Is Nothing Then
For i As Integer = 0 To mImageList.Count - 1
e.Graphics.DrawImage(CType(mImageList.Item(i), Image), 0, 0)
Catch ex As Exception