By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,170 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,170 IT Pros & Developers. It's quick & easy.

Bitmap/Image data type

P: n/a
It seems that no matter how I load a bitmap into memory it remains attached
to whatever I used to create it. If I obtained the bitmap from a file the
file stays locked or if it came from a stream I can't close the stream. I
don't see why it is doing this when it loads the full image into memory
anyway. I could understand it doing this if the bitmap discards it's data
when not needed but it doesn't seem to do this. The only way I've found to
fully detach a bitmap from it's source is to create a new bitmap from the
previous one but this slows things down considerably when loading a lot of
images and doubles the memory use while loading large images. Is there any
other way?

Thanks,
Michael
Apr 6 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Michael C" <no****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
| It seems that no matter how I load a bitmap into memory it remains
attached
| to whatever I used to create it. If I obtained the bitmap from a file the
| file stays locked or if it came from a stream I can't close the stream. I
| don't see why it is doing this when it loads the full image into memory
| anyway. I could understand it doing this if the bitmap discards it's data
| when not needed but it doesn't seem to do this. The only way I've found to
| fully detach a bitmap from it's source is to create a new bitmap from the
| previous one but this slows things down considerably when loading a lot of
| images and doubles the memory use while loading large images. Is there any
| other way?
|
| Thanks,
| Michael
|
|

Make sure you dispose the Image after having done with it. One way to
automate this is by applying the using idiom like this:

using (Image imageFile = Image.FromFile(.....)) {
// draw to screen or whatever...
...

} // close underlying stream

Willy.
Apr 6 '06 #2

P: n/a
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:uA**************@TK2MSFTNGP05.phx.gbl...
Make sure you dispose the Image after having done with it. One way to
automate this is by applying the using idiom like this:

using (Image imageFile = Image.FromFile(.....)) {
// draw to screen or whatever...
...

} // close underlying stream


That's ok but the problem in my case is the image can get passed around all
over the place. If the image is attached to a stream then I need to pass the
stream around with the image everywhere it goes. Usually I'll have a method
which gets and image from a various places (eg scanner, camera, database or
file) and I don't want to have to return the stream with the image. All I
want is an image that is totally detatched from the stream but this doesn't
seem possible without completely duplicating the image.

Michael
Apr 6 '06 #3

P: n/a
Yes, when you open a bitmap from a Stream, the Stream must remain open. When
you open it from a file, the file remains locked.

I'm not sure exactly what you are doing with the image when you pass it
around, or where exactly you are passing it around. What about reading in
the image as an array of bytes and passing that around?

"Michael C" wrote:
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:uA**************@TK2MSFTNGP05.phx.gbl...
Make sure you dispose the Image after having done with it. One way to
automate this is by applying the using idiom like this:

using (Image imageFile = Image.FromFile(.....)) {
// draw to screen or whatever...
...

} // close underlying stream


That's ok but the problem in my case is the image can get passed around all
over the place. If the image is attached to a stream then I need to pass the
stream around with the image everywhere it goes. Usually I'll have a method
which gets and image from a various places (eg scanner, camera, database or
file) and I don't want to have to return the stream with the image. All I
want is an image that is totally detatched from the stream but this doesn't
seem possible without completely duplicating the image.

Michael

Apr 6 '06 #4

P: n/a
"rmacias" <rm*****@newsgroup.nospam> wrote in message
news:B2**********************************@microsof t.com...
Yes, when you open a bitmap from a Stream, the Stream must remain open.
When
you open it from a file, the file remains locked.
Do you know the reason behind this? It doesn't seem necessary to me if
everything is copied into memory anyway.
I'm not sure exactly what you are doing with the image when you pass it
around, or where exactly you are passing it around. What about reading in
the image as an array of bytes and passing that around?


Typically an image will be grabbed from a source (could be database, file,
directshow, twain, wia, clipboard or even custom hardware). The image will
be passed to a control that displays a small version of it. If the user
double clicks it it gets passed to another form to display full screen. If
the user decides to keep the image it is then passed to be saved into the
database and passed to another form which displays all images. From there it
can be passed around to all sorts of places to display, edit, print, delete,
email it etc. It's also stored in an image cache to speed up loading if
users are scrolling between images.

To keep the stream open or the file locked during all of this is impracticle
(eg if a user imports a file into my app the file should then be able to be
deleted (or if the user so specifies then my app will delete it)). Currently
I just create a copy of the bitmap which does work but is quite inefficient.
I've ordered a book about dot net imagine so hopefully that will shed some
light on what is actually happening. The help is pretty poor really and
usually only explains what obvious anyway. :-)

Michael
Apr 7 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.