473,402 Members | 2,053 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,402 software developers and data experts.

disposing or killing a reference to a Bitmap

I have a "Plot" button the code associated with which (when Clicked) is
as follows
private: System::Void showPic_Click(System::Object * sender,
System::EventArgs * e)
{
/* code to use Matlab to create a 'bmp' and save to

C:\tmp\matlabFromNET_TRY2\somefile.bmp
*/

Bitmap* MyImage;
MyImage =new Bitmap("C:\\tmp\\matlabFromNET_TRY2\\somefile.bmp" );
pictureBox1->Image = MyImage;

}
What basicaly happens is everytime the button is clicked the file
'somefile.bmp' is modified by a Matlab code peice at the start pf the
function, and this file is reloaded into a pictureBox named
'pictureBox1'. The issue I am having is that the first time the button
is clicked the expected image is loaded, but the second time the button
is clicked the old image remains. This is because the bmp is locked
when its loaded into the picture box and no other user or the Matlab
code at the beginning can save changes to the bmp when the button is
clicked again. How would I free the Bitmap at the end of the function
to ensure that the next time this button is clicked, Matlab will be
able to make changes to the 'bmp'

Sep 25 '06 #1
2 1188
What basicaly happens is everytime the button is clicked the file
'somefile.bmp' is modified by a Matlab code peice at the start pf the
function, and this file is reloaded into a pictureBox named
'pictureBox1'. The issue I am having is that the first time the button
is clicked the expected image is loaded, but the second time the button
is clicked the old image remains. This is because the bmp is locked
when its loaded into the picture box and no other user or the Matlab
code at the beginning can save changes to the bmp when the button is
clicked again. How would I free the Bitmap at the end of the function
to ensure that the next time this button is clicked, Matlab will be
able to make changes to the 'bmp'
A simple solution would be to create a secondary bitmap, and copy the Matlab
bitmap into it.
You would have the overhead of an extra bitmap, but none of the locking
issues.

Then you can simply Dispose the image at the end of your functioncall.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Sep 25 '06 #2
AM
sound advice!
worked perfectly fine...n was so simple!(one of those times when u
think...damn why didnt I think of tht!)

Thanks..

if someone could use the code here it is
private: System::Void showPic_Click(System::Object * sender,
System::EventArgs * e)
{

Bitmap* MyImage, *MyImage2;
MyImage =new
Bitmap("C:\\tmp\\matlabFromNET_TRY2\\somefile.bmp" );
MyImage2=new Bitmap(MyImage);
pictureBox1->Image = MyImage2;
MyImage->Dispose();
}

----------------------------------------------------------
Bruno van Dooren [MVP VC++] wrote:
What basicaly happens is everytime the button is clicked the file
'somefile.bmp' is modified by a Matlab code peice at the start pf the
function, and this file is reloaded into a pictureBox named
'pictureBox1'. The issue I am having is that the first time the button
is clicked the expected image is loaded, but the second time the button
is clicked the old image remains. This is because the bmp is locked
when its loaded into the picture box and no other user or the Matlab
code at the beginning can save changes to the bmp when the button is
clicked again. How would I free the Bitmap at the end of the function
to ensure that the next time this button is clicked, Matlab will be
able to make changes to the 'bmp'

A simple solution would be to create a secondary bitmap, and copy the Matlab
bitmap into it.
You would have the overhead of an extra bitmap, but none of the locking
issues.

Then you can simply Dispose the image at the end of your functioncall.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Sep 25 '06 #3

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

Similar topics

6
by: Colin Steadman | last post by:
I have created a function to kill all session variables that aren't in a safe list. This is the function - Sub PurgeSessionVariables For Each Item In Session.Contents Select Case Trim(Item)...
1
by: Kent | last post by:
Hi! I am working with an obscure graphics library in school as a university C++ programming project. The graphics library has a class kalled Bitmap wich you use to draw graphics (you can "stamp...
4
by: Dakkar | last post by:
I have a program with windows forms and after execution of my program im making it invisible for working background progress and i have a dispose function like this protected override void...
6
by: Dennis | last post by:
I have a global variable that is of type Image. I set this to different images in different routins using BitBlt to copy from the screen. If I dispose of the variable image after I'm thru with...
10
by: Dennis | last post by:
I don't think I clearly stated my problem in my prior question so let me try again. I have the following: Private myobject as Bitmap myobject = mybitmap (created from a part of the screen) ...
4
by: Qwert | last post by:
Hello, I have a listview with an image list. After dispoing the images and the image list, the bitmap files remain locked: REM Create. objImage = Image.FromFile(strBmp) If...
0
by: Gman | last post by:
Hi, Objective: Draw a grid on a bitmap and set this as a panel's image. (Rather than draw the grid directly on the panel and redraw repeatedly in the paint event.) Problem: It works fine....
3
by: Marc | last post by:
Guys the below code is not working ( i know i am trying to reference a function!) . Im a beginner so does anyone know how i could reference the bitmap? Private Sub...
29
by: Jerry Spence1 | last post by:
I'm rather confused as to whether something should be disposed of, or not. What is the general rule? How can you be sure of doing the right thing? I've heard about disposing unmanaged resources but...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.