Re: loading an image in to Bitmap
Chris Anderson <[email protected]> Thu, 12 Jul 2007 00:34:18 +0100
| Newsgroups | gmane.comp.windows.devel.dotnet.web |
|---|---|
| Message-ID | <[email protected]> |
IIRC loading a Bitmap actually memory maps the file and so locks the file. (This results in the file not having to be actually read from disk until it's required.) Try using Clone on the loaded Bitmap to create a new copy of the bitmap, and then Dispose the one you opened from the file. Or if Clone doesn't work, create a new Bitmap with the same size and colour depth, create Graphics object from it, and use DrawImage to effectively BitBlt the image to the new in-memory one. Also note that disposing the bitmap may not *immediately* release the lock on the file. Why is the file on disk? I'm guessing (based on this being a web list) that it's being uploaded? If this is the case, I'm wondering if the upload can be performed into a memory stream instead of a disk-based file? Chris > I'm trying to load an image in to the bitmap class. It is working ok, > but I need to load it in to the bitmap class and not reference the file > on the computer anymore. Eg: > > Bitmap Photo = new (Bitmap)Bitmap.FromFile(FileName); > File.Delete(FileName); > > The second line will throw an error saying the file is in use. I have > tried all difference combinations of new Bitmap() but all seem to keep > referencing the file on the disk, is there any way to do this (just > keep > the image in memory)? > > Thank you, =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com