dotgnu-pnet
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pnet-developers] Bitmap(Stream stream) behaviour?


From: Russtopia
Subject: [Pnet-developers] Bitmap(Stream stream) behaviour?
Date: Wed, 1 Oct 2003 10:27:52 -0600 (MDT)

Hi all,

(Firstly -- apologies in advance for posting what might be an FAQ -- I
know it's good to lurk for a while first when joining a list, but if I
don't post this now I'll probably forget and never get it done...)

I'm pretty new to the whole CLR thing. I've been working on some code that
loads bitmap (.BMP format) data into Bitmap objects. It appears that with
Microsoft's .NET framework, the constructor

Bitmap(Stream stream)

always 'rewinds' the supplied stream before attempting to load data. I
wanted to make a method that loaded my own file format, consisting of some
header data preceding the standard BMP data; so my initial attempts passed
the 'middle' of a stream to the Bitmap constructor. This doesn't work though,
as the constructor seems to insist on rewinding and reading from the start of
the stream. The final procedure I came up with was:

1) Create FileStream object 'fs'
2) Create a BinaryReader object 'br' from 'fs'
3) Read in binary header values using 'br'
4) Read the remainder of the file (BMP format data) into byteArray[]
5) Create a MemoryStream 'ms' from byteArray[]
6) create new bitmap: bitmap = new Bitmap(ms);

There isn't any mention in the .NET framework docs that the stream-based
constructor for Bitmap implicitly rewinds the stream (or maybe it makes
a copy of the stream and rewinds that? Haven't tested) -- it would
seem, to my not-so-common sense, that one should just be able to pass
an open FileStream or BinaryReader (with their current file positions) in
order to read an 'embedded' bitmap from a file, but this isn't the case.

I just thought this might be a good 'heads-up' to the dotGNU developers,
so that this quirk can be duplicated in the dotGNU class libs.

-Russ Magee




reply via email to

[Prev in Thread] Current Thread [Next in Thread]