Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Bitmaps from streams - duplicated data in memory?

Reply
 
Old 06-20-2008   #1 (permalink)
Chris Ashley


 
 

Bitmaps from streams - duplicated data in memory?

Hi,

If I create a Bitmap object from a stream, is the data making up the
image from that stream duplicated in the Bitmap object, or does the
Bitmap just point to the stream somehow without holding any image
data?

I did notice that if I populated a Bitmap object from a MemoryStream,
if I closed the MemoryStream I got a GDI error when I tried to save
the Bitmap, so I assumed it was the latter. Just looking for
confirmation.

Thanks,

Chris

My System SpecsSystem Spec
Old 06-20-2008   #2 (permalink)
Jeroen Mostert


 
 

Re: Bitmaps from streams - duplicated data in memory?

Chris Ashley wrote:
Quote:

> If I create a Bitmap object from a stream, is the data making up the
> image from that stream duplicated in the Bitmap object or does the Bitmap
> just point to the stream somehow without holding any image data?
It depends on whether the stream is seekable. If it is not, the data will be
copied. If it is, it will use the stream directly.

That's an implementation detail, though. The documentation for Bitmap
explicitly states: "You must keep the stream open for the lifetime of the
Bitmap." Bitmap could one day read lazily from non-seekable streams if it so
desired.
Quote:

> I did notice that if I populated a Bitmap object from a MemoryStream,
> if I closed the MemoryStream I got a GDI error when I tried to save
> the Bitmap, so I assumed it was the latter. Just looking for
> confirmation.
>
Now you know you shouldn't do that, even if it happens to work on some
streams. :-)

--
J.
http://symbolsprose.blogspot.com
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
any way to enable "alternate data streams" in Vista ? Vista file management
Alternate Data Streams on files PowerShell
Bitmaps Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46