Search code examples
c#bitmapdispose

C#: Dispose() a Bitmap object after call Bitmap.save()?


I have this:

Bitmap bmp = new Bitmap(image);
//image processing
bmp.Save(path + fileName);

and I want to know if I need to call bmp.Dispose() after this code. Thanks in advance.


Solution

  • I would use using block and Path.Combine

    using(var bmp = new Bitmap(image))
    {
        // image processing
        bmp.Save(Path.Combine(path ,fileName));
    }