Jump to content
Sign in to follow this  
Guest titan_ve

Dispose, Close GDI+

Recommended Posts

Guest titan_ve

Hello!!Well, I'm having a problem trying to find a method/function to release a file that I am opening with this _img = Bitmap::FromFile(L"picture.bmp");I can open it and DrawImage it, but then I need to overwrite the file "picture.bmp", but it seems that the FromFile method is blocking it, so I need a function/method to tell GDI+ to release it...Does anyone know anything about this??Im trying to use graphics.Dispose() and graphics.Close() but when I compile it says that those methods doesn't exist on "gdiGdiplusGraphics.h"Thank you in advanceRafa

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

First, bad practice to name identifiers with an initial underscore.Try Dispose() 'ing the Bitmap: _img.Dispose();Why are you trying to overwrite the picture.bmp? Are you drawing on it programatically? Maybe what you want to do is do your work on a .tmp file, then once complete do some renaming, much like you would do when working with a text file. This sort of transaction handling helps if your program doesn't get to complete for some reason.

Share this post


Link to post
Share on other sites
Guest titan_ve

Hi Patrick!!, thanks for ur answer!!! =)Well, Im gonna try to do what you suggest!.But, don't you think it's wierd that I cannot release the graphics??;)Rafa

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Rafa,>But, don't you think it's wierd that I cannot release the>graphics??I'm assuming you are using C# (given .dispose() is a gc thing). You can't "dispose" a class, just an instantiated object.You can instantiate or get a graphics object like this: Graphics g = new Graphics(); // One way to get an objectand then dispose of it like this: g.Dispose(); // Now available for garbage collectionNote that "Graphics" is the Class (object type), g is the object, Graphics() is the constructor, and Dispose() is an object method. Dispose is not a static method which could be called with: Graphics.Dispose(); // Wrong, not a static methodas static methods do not refer to instance objects. To dispose of an object, you clearly have to have one first, hence it is non-static.Hope that clears it up for you.

Share this post


Link to post
Share on other sites
Guest titan_ve

Thanks Patrick for your help, Im creating the Graphics object like this:HDC hdc = pelement->hdc;if (hdc){ Graphics graphics(hdc);...}so, i tryed this:graphics.Dispose(), but it says that it doesnt have that methodRafa

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Well keep in mind that: Graphics graphics(hdc); // Declaration in C# does not allocateis only a declaration of a reference (ie not a value) type in C#, unlike in C++, this does not allocate memory, or create an object, only a "pointer" that does not yet point to anything. I think what you need is: Graphics graphics = new Graphics(hdc); // Instantiates graphicsalthough I'm not sure that such a constructor (with an hdc) exists.Remember, you have to have an object first, before you will have any member fields, or methods available, unless they are static.Also, if you are defining it inside a scope { here }, and then leave that scope, any variables go out of scope (and existance) and so you will need to Dispose() of them before leaving that scope (or hope that it is done for you by the gc).Patrick

Share this post


Link to post
Share on other sites
Guest titan_ve

ok!, I'm understanding right now, well, I'm going to make some research if i could make that new Graphics(hdc), thank you very much Patrick!!!, this is my first time with C++, and trying to understand all those types of String formats, I kinda miss java, just STRING or CHAR[], lolthanks!Rafa

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

>ok!, I'm understanding right now, well, I'm going to make>some research if i could make that new Graphics(hdc), thank>you very much Patrick!!!, this is my first time with C++, and>trying to understand all those types of String formats, I>kinda miss java, just STRING or CHAR[], lolIf you are programming in C++, then you are not programming in managed code, and there are no Dispose() functions. In C++ you manage your own memory, and so you must delete your objects with Destructors. delete graphics; // Use delete for objects you created with newSorry, given your initial question, as I mentioned, I was assuming you were programming in C#.

Share this post


Link to post
Share on other sites
Guest titan_ve

quick question: can I make GAUGES for FS9/FSX in C#???I think that will be better, don't you think??do u have msn messenger??Rafa

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

>quick question: can I make GAUGES for FS9/FSX in C#???Quick answer: No. You can program portions of code using a managed language and interface it using what is called "marshalling", but this is complicated. If you were going to do it (and it has been done) you would likely use managed C++, rather than C# anyway.>I think that will be better, don't you think??Not really. C# is more for building tools, or programming non real-time simulation software. For a game program like FS that is real time, C++ is superior.>do u have msn messenger??Yes, but you are better off posting questions here, as other that may know more than I can also put in their two-cents. If you want to contact me privately you can email me or send me a PM.

Share this post


Link to post
Share on other sites
Guest titan_ve

Ok Patrick!Well I'll keep posting, you are right is better so anyone could see the messages.Well, thanks for your GREAT help trying to let me understand what this is all about!!!I'll let you know about what I will be founding!!Thank you very much...!Rafa

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...