473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Bitmap/Image data type

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
4 3727

"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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it...
2
by: | last post by:
Hello All, I am writing a web application that reads a bitmap from a file and outputing it to a HTTP response stream to return the image to the requesting client. The image file is a regular...
6
by: Lespaul36 | last post by:
From what I have read, there isn't really a converter to icon format..it becomes a png file. I tried: 1: Dim bmp As Bitmap = CType(Bitmap.FromFile("C:\myfolder\file.bmp"), Bitmap) 2: ...
3
by: Sharon | last post by:
I have a buffer of byte that contains a raw data of a 1 byte-per-pixel image data. I need to convert this buffer to a Bitmap of Format32bppArgb and to a Bitmap of Format24bppRgb. Can anybody...
7
by: Fir5tSight | last post by:
Hi All, I used the following code in C#: using System.Drawing; //blah blah blah Bitmap bmp = new Bitmap();
6
by: Dave Harvey | last post by:
I have developed a standard .NET control which displays medical images and works fine in applications, but increasingly, my customers are wishing to use it in an ASP.NET environment, so I am...
1
by: Smokey Grindel | last post by:
I have a bitmap object I want to return as a JPEG image with a compression set at 90% and progressive passes enabled, how can I do this in .NET 2.0? Progressive passes are not necessary but the...
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
1
by: Robin Becker | last post by:
I'm having trouble with defining a completely transparent bitmap for use as a stipple in a canvas import Tkinter Tkinter._default_root.tk.call('image','create', 'bitmap', 'gray0',...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.