Error when attempting to open files



Hi,

I have the following code:

private Image _image;

public MyImage(string filename)
{
FileStream file = File.Open(filename, FileMode.Open);
_image = Image.FromStream(file);
//file.Close();
}

Which essentially is used for passing a file name of an image, which is
then used for various things such as creating a thumbnail.

The problem I'm having is that if I create a thumbnail of the image that
is open, then reload the page in my browser, I get an error that reads:

"The process cannot access the file ... because it is being used by
another process"

So I figured that was because I forget to close the file stream after
opening the image file, so I added in the line of code that is commented
out in the example above.

Now when I run the code I receive:

"Out of memory."

If I attempt to create a thumbnail image with:

_image = _image.GetThumbnailImage(size, size, null, IntPtr.Zero);)

or:

"A generic error occurred in GDI+."

If I simply write the contents of the image to the browser:

_image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

When I don't close the file stream it works okay for the first time I
view the page (as a thumbnail, or the full-sized image), but gives the
error about it being in use if I refresh. It doesn't work at all when I
close the file stream.

Any ideas what I'm doing wrong here?

--
Dylan Parry
http://electricfreedom.org | http://webpageworkshop.co.uk

The opinions stated above are not necessarily representative of
those of my cats. All opinions expressed are entirely your own.
.



Relevant Pages

  • Re: What is the best way to resize an image?
    ... Sure Rudy: ... The browser will resize it to the specified height and width. ... >> links on each thumbnail to the full-sized image, you may not want to make ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Creating Thumbnail image of a webpage ?
    ... for is "Create a small image (Thumbnail) of a webpage. ... PHP is not a browser, so it has no clue how to handle HTML/CSS/etc., so it would have to be told this. ... Then you could fire open a quick instance of whatever browser or COM instance you desire, fire a snapshot utility, save that and resample with PHP's image functions, GD or ImageMagick. ...
    (comp.lang.php)
  • Re: Pictures wont store in users cache
    ... Interesting too, because when you close the page in the browser, the script ... clears itself from the cache files. ... > you might have your browser's setting "check for changed content every time site> is visited" or eqivalent for whatever browser you use. ... I've built a web site> and none of the pictures I've put into it are> caching and the photo gallery (100+ pictures with auto thumbnail) thumbnail> doesn't cache either. ...
    (microsoft.public.frontpage.client)
  • Re: D80 - high ISO noise
    ... I went back and checked - if you click on the thumbnail it takes you to ... a bitmap file. ... with my browser, since BMP is native to Windows, not to unix. ... which I don't think can even be included in a BMP image. ...
    (rec.photo.digital.slr-systems)
  • Re: Image size question
    ... >> I have an app that has many subdirectories containing one or more ... >> The thumbnail idea also presents the same problem. ... tells the browser not the expect a webpage but rather an image. ... But does it appear somewhere in the current webpage or open up a new ...
    (microsoft.public.dotnet.framework.aspnet)