Re: Out of memory exception loading a bitmap from a stream

Tech-Archive recommends: Fix windows errors by optimizing your registry



It's an icon file as a resource.

Yes, later I'll modify the code to construct the correct name - the code I
posted is what I've been trying to get working as a test - but it needs to
be working first. Any ideas?

"Alex Feinman [MVP]" <public_news@xxxxxxxxxxxxxxx> wrote in message
news:ul0$iDnXGHA.1204@xxxxxxxxxxxxxxxxxxxxxxx
Your stream is called IconStream. Is it an icon file indeed, or just a
misnomer?
Also, avoid using resources by index. You never know which one you are
actually loading. Use the actual name

"Rick" <rickspiewak@xxxxxxxxxxxxxx> wrote in message
news:1144873910.849287.64730@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm trying to extract an icon from a resource in a dll. The following
sequence:

Dim MyAssemblies() As [Assembly]
.
.
ResourceNames = MyAssemblies(i).GetManifestResourceNames
IconStream = _
MyAssemblies(i).GetManifestResourceStream(ResourceNames(0))
Dim Icon As New Bitmap(IconStream)

Results in an exception:

System.OutOfMemoryException was unhandled
Message="OutOfMemoryException"
StackTrace:
at Microsoft.AGL.Common.MISC.HandleAr()
at System.Drawing.Bitmap._InitFromMemoryStream()
at System.Drawing.Bitmap..ctor()
at ...(Application stack trace)

There is plenty of both storage and program memory left on the device,
and the stream (IconStream) is small (length = 1078). Any ideas? Should
I just punt and put the icon in a file? (not as general)




.


Quantcast