Page 1 of 1

[C#] Loading bitmap from a stream

Posted: Wed 14 Feb, 2007 2:28 pm
by King Harold
you're probably thinking "what?!? he can't even do that?!"
well I can, but I want to load it from the stream starting at a position other than zero. Simply setting the position (using seek or just writing to the position) does not seem to work. I didn't find anything using google, so I feared it may not be possible, but it almost has to be, it's something so simple..

I'd rather not do weird things like copying byte arrays to bitmap-data things, I guess that would work but it shouldn't have to be that complicated.

If that's the only possibility then ofcourse it's ok..

Posted: Wed 14 Feb, 2007 3:03 pm
by benryves
I'm surprised seeking doesn't work, but can't verify it from here.

If it's a huge problem, seek to the right place, create a new MemoryStream and dump the data from the file to the MemoryStream, then load from the MemoryStream.

Posted: Wed 14 Feb, 2007 4:54 pm
by King Harold
Ah yes didn't think of that :P
Many thanks :)

Posted: Wed 14 Feb, 2007 5:10 pm
by benryves
I've used it with and old version of MDX that was incredibly slow to load textures from Bitmaps. I'd create a new MemoryStream, Bitmap.Save into it then load the texture from the stream (took a 2 minute load to a < 2s load). ;)