Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Image Dispose

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
steve - 09 Sep 2004 21:15 GMT
Here's code that works fine.  It gets an Image from a file stream, and
raises an event passing the image object, then closes the fileStream.

Image imgObj = Image.FromStream(fStream,true);
// Raise Event SingleImageCaptured and pass Image object data
OnSingleImageCaptured(new RemoteDeviceEventArgs(imgObj ));
fStream.Close();

I'd like to do something like this to Dispose of the Image as soon as it's
done being used.

using(Image imgObj = Image.FromStream(fStream,true))
{
    // Raise Event SingleImageCaptured and pass Image object data
    OnSingleImageCaptured(new RemoteDeviceEventArgs(copyImage));
    fStream.Close();
}

The above code raises an System.Drawing exception "Invalid parameter used."
I realize the Image is probably disposed before it's used in the client who
subscribes to OnSingleImageCaptured().  My goal is to clean up (Dispose) the
Image object resource as soon as I'm done with it rather than let the GC
handle it sometime in the very far future.  Is it possible and Dispose of
the Image object and should it really be done at this point?
Herfried K. Wagner [MVP] - 09 Sep 2004 21:52 GMT
* "steve" <csufsurfer@yahoo.com> scripsit:
> Here's code that works fine.  It gets an Image from a file stream, and
> raises an event passing the image object, then closes the fileStream.

You must not close the stream the image is created from when you are
keeping using the image constructed from the stream.

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/

steve - 10 Sep 2004 07:00 GMT
Fair enough.

> * "steve" <csufsurfer@yahoo.com> scripsit:
> > Here's code that works fine.  It gets an Image from a file stream, and
> > raises an event passing the image object, then closes the fileStream.
>
> You must not close the stream the image is created from when you are
> keeping using the image constructed from the stream.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.