I'm trying to compare two images and delete the second one if they are the same image. When my program goes to delete a file, it throws an error: The process cannot access the file "C:\Temp\Image.jpg" because it is being used by another process
It seems to be an issue with this method not closing the bitmap file, but I have yet to find out a way to release the bitmap from system memory in order to delete it
    public static bool ImageCompareString(Bitmap firstImage, Bitmap secondImage)
    {
        MemoryStream ms = new MemoryStream();
        firstImage.Save(ms, ImageFormat.Png);
        string firstBitmap = Convert.ToBase64String(ms.ToArray());
        ms.Position = 0;
        secondImage.Save(ms, ImageFormat.Png);
        string secondBitmap = Convert.ToBase64String(ms.ToArray());
        if (firstBitmap.Equals(secondBitmap))
        {
            ms.Close();
            return true;
        }
        else 
        {
            ms.Close();
            return false;
        }
    }
 
     
    