473,508 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Releasing a bitmap after use

Hi,

I have a windows application that contains a PictureBox control. I am using
the statement

PicBox.Image = new Bitmap ("C:\Pic.jpg");

to load a file into the PictureBox to be displayed.

I am using a timer control to rotate the pictures that I display Pic0 - Pic9
every 30 seconds.

However, as I change the picture to the the next one in the sequence, the
old picture is not being "released" and windows will not allow me to edit the
name etc until the entire application is closed down.

How do I drop the connection to the image file when I no longer wish to
display it in my PictureBox so that the file can be edited outside of my
application.

Many thanks in advance
Aug 8 '06 #1
10 2011
Hi,

The image is still in use. Do this, preload all the images in an array then
rotate them to the picturebox

Also I would consider the use of a single animated gif
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"hplloyd" <hp*****@discussions.microsoft.comwrote in message
news:0D**********************************@microsof t.com...
Hi,

I have a windows application that contains a PictureBox control. I am
using
the statement

PicBox.Image = new Bitmap ("C:\Pic.jpg");

to load a file into the PictureBox to be displayed.

I am using a timer control to rotate the pictures that I display Pic0 -
Pic9
every 30 seconds.

However, as I change the picture to the the next one in the sequence, the
old picture is not being "released" and windows will not allow me to edit
the
name etc until the entire application is closed down.

How do I drop the connection to the image file when I no longer wish to
display it in my PictureBox so that the file can be edited outside of my
application.

Many thanks in advance

Aug 8 '06 #2
Mel
Try loading the picture using a filestream

uisng (FileStream fs = new
FileStream(@"C:\Pic.jpg",FileMode.Open,FileAccess. Read,FileShare.Read))
{
PicBox.Image = Image.FromStream(fs);
}
"hplloyd" <hp*****@discussions.microsoft.comwrote in message
news:0D**********************************@microsof t.com...
Hi,

I have a windows application that contains a PictureBox control. I am
using
the statement

PicBox.Image = new Bitmap ("C:\Pic.jpg");

to load a file into the PictureBox to be displayed.

I am using a timer control to rotate the pictures that I display Pic0 -
Pic9
every 30 seconds.

However, as I change the picture to the the next one in the sequence, the
old picture is not being "released" and windows will not allow me to edit
the
name etc until the entire application is closed down.

How do I drop the connection to the image file when I no longer wish to
display it in my PictureBox so that the file can be edited outside of my
application.

Many thanks in advance

Aug 8 '06 #3
Thanks for your help however pre-loading them will not actually help in my
circumstances. (the example I gave is not my real life example, just a subset
of it)

Is there any way that I can release an image so that it is no longer in use
after I have finished displaying it?

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

The image is still in use. Do this, preload all the images in an array then
rotate them to the picturebox

Also I would consider the use of a single animated gif
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"hplloyd" <hp*****@discussions.microsoft.comwrote in message
news:0D**********************************@microsof t.com...
Hi,

I have a windows application that contains a PictureBox control. I am
using
the statement

PicBox.Image = new Bitmap ("C:\Pic.jpg");

to load a file into the PictureBox to be displayed.

I am using a timer control to rotate the pictures that I display Pic0 -
Pic9
every 30 seconds.

However, as I change the picture to the the next one in the sequence, the
old picture is not being "released" and windows will not allow me to edit
the
name etc until the entire application is closed down.

How do I drop the connection to the image file when I no longer wish to
display it in my PictureBox so that the file can be edited outside of my
application.

Many thanks in advance


Aug 8 '06 #4
Try loading the image from disk as suggested into a new Image object, and
then assign that to the PictureBox's Image property. Then, you can call
Dispose on your original Image object.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"hplloyd" wrote:
Hi,

I have a windows application that contains a PictureBox control. I am using
the statement

PicBox.Image = new Bitmap ("C:\Pic.jpg");

to load a file into the PictureBox to be displayed.

I am using a timer control to rotate the pictures that I display Pic0 - Pic9
every 30 seconds.

However, as I change the picture to the the next one in the sequence, the
old picture is not being "released" and windows will not allow me to edit the
name etc until the entire application is closed down.

How do I drop the connection to the image file when I no longer wish to
display it in my PictureBox so that the file can be edited outside of my
application.

Many thanks in advance
Aug 8 '06 #5
Thanks that works perfectly

"Mel" wrote:
Try loading the picture using a filestream

uisng (FileStream fs = new
FileStream(@"C:\Pic.jpg",FileMode.Open,FileAccess. Read,FileShare.Read))
{
PicBox.Image = Image.FromStream(fs);
}
"hplloyd" <hp*****@discussions.microsoft.comwrote in message
news:0D**********************************@microsof t.com...
Hi,

I have a windows application that contains a PictureBox control. I am
using
the statement

PicBox.Image = new Bitmap ("C:\Pic.jpg");

to load a file into the PictureBox to be displayed.

I am using a timer control to rotate the pictures that I display Pic0 -
Pic9
every 30 seconds.

However, as I change the picture to the the next one in the sequence, the
old picture is not being "released" and windows will not allow me to edit
the
name etc until the entire application is closed down.

How do I drop the connection to the image file when I no longer wish to
display it in my PictureBox so that the file can be edited outside of my
application.

Many thanks in advance


Aug 8 '06 #6
Hi,

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:C5**********************************@microsof t.com...
Try loading the image from disk as suggested into a new Image object, and
then assign that to the PictureBox's Image property. Then, you can call
Dispose on your original Image object.
Peter
Does this mean that PictureBox makes a copy of the image?

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Aug 8 '06 #7
Hi,

"Mel" <Me************@insdirect.comwrote in message
news:us**************@TK2MSFTNGP05.phx.gbl...
Try loading the picture using a filestream

uisng (FileStream fs = new
FileStream(@"C:\Pic.jpg",FileMode.Open,FileAccess. Read,FileShare.Read))
{
PicBox.Image = Image.FromStream(fs);
}
The stream will be kept open while the image is in memory.

The only way you can not use the file anymore is if you copy the file to a
MemoryStream and then use Image.FromStream using this memorystream
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Aug 8 '06 #8
Ignacio,
Who knows? When I tried it the image didn't disappear so...
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:C5**********************************@microsof t.com...
Try loading the image from disk as suggested into a new Image object, and
then assign that to the PictureBox's Image property. Then, you can call
Dispose on your original Image object.
Peter

Does this mean that PictureBox makes a copy of the image?

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Aug 9 '06 #9
Hi,
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:DD**********************************@microsof t.com...
Ignacio,
Who knows? When I tried it the image didn't disappear so...

Did not disappear from where?

I havent test it but according to the docs the file stay open until the
Image instance is disposed.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Aug 9 '06 #10
Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in
message news:C5**********************************@microsof t.com...
Try loading the image from disk as suggested into a new Image
object, and then assign that to the PictureBox's Image property.
Then, you can call Dispose on your original Image object.
Peter

Does this mean that PictureBox makes a copy of the image?
Yes, as it will post-process it according to the pictorebox
properties how to display the image (stretched, normal etc.).

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Aug 10 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3030
by: lebo | last post by:
Hi I'm trying to understand how Python handles memory usage and dynamic object loading and unloading. Problem to solve? Build a very low memory footprint (non-GUI) Python application for...
8
3297
by: Nathan Sokalski | last post by:
I am trying to write code to rotate a graphic that I have. Here is the code I am currently using: Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("images/frog.gif"))) Dim...
7
8223
by: Fir5tSight | last post by:
Hi All, I used the following code in C#: using System.Drawing; //blah blah blah Bitmap bmp = new Bitmap();
14
11861
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...
0
2850
by: benfly08 | last post by:
Hi, guys. I have a program to draw bar/pie chart based on the data i hard coded in it. However, my image comes with "BLACK" background color. I don't know how to fix this. The code snippet is...
8
4290
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the...
6
2436
by: \Frank\ | last post by:
I trying to learn what a Bitmap is. Not a Managed Bitmap Object but one that, for example, comes from the clipboard with CF_BITMAP. I'm guessing that a CompatableBitmap is an array of indices...
2
2585
by: Peter Oliphant | last post by:
I want to create a new Bitmap which is a portion of an existing Bitmap. For example, if I have a Bitmap that is 100x100 in size I might want to create a new Bitmap that is equivalent to the one...
5
2559
by: =?Utf-8?B?QVRU?= | last post by:
I have a bitmap of 100X100. On the load, the bitmap is created by a function (createimage()). On my OnPaint, I draw the image back to the screen (e.Graphics.DrawImage( bitmap, destrect)). Now,...
0
7225
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
7382
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.