[C#] Loading bitmap from a stream

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

[C#] Loading bitmap from a stream

Post 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..
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post 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.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Ah yes didn't think of that :P
Many thanks :)
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post 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). ;)
Post Reply