Hey,
I want to create an image from a file, and then have the file deleted (or moved) after. How could I achieve this? I tried using using(), streams, Bitmaps etc. I'm completely stumped. Any help would be great.
Thanks

Edit, the problem is that I cannot delete/move the file, as it is in use (by the image I presume).

Edited 6 Years Ago by bbman: n/a

System.IO.File.Delete(FilePath);

No, the problem is that I cannot delete it because the image is using it.

Here is the code:
http://pastebin.org/302679
a = string[] of files.
It's a bulk uploader. Now oddly, when the resize function (below) is called, it actually works - the file is released.

private Image ResizeImage(Image img, int width, int height, bool aspect)
{
    if (aspect)
    {
        if (((width * 100) / img.Width)
            < ((height * 100) / img.Height))
            height = (img.Height * width) / img.Width;
        else
            width = (img.Width * height) / img.Height;
    }
    img = (Image)(new Bitmap(img, width, height));
    return img;
}

Edited 6 Years Ago by bbman: n/a

Reasonable! :) should have typical copy on temp folder and work on it, if your operation successed then you delete the original one.

Edited 6 Years Ago by Ramy Mahrous: n/a

My bad! It was an error with something else.

Edit: Nope. I fixed it. I want something a little less resource consuming. Writing files everywhere will just slow it down.

Edited 6 Years Ago by bbman: n/a

Work with MemoryStream it may help to separate your operations and the physical file.

Edited 6 Years Ago by Ramy Mahrous: n/a

Work with MemoryStream it may help to separate your operations and the physical file.

Thanks for your help. I did:

using (Stream st = new FileStream(a[i], FileMode.Open))
{
    img = Image.FromStream(st);
    st.Close();
}
This question has already been answered. Start a new discussion instead.