Bitmap PixelFormat properly detected only on second test
<p>I need a screenshot saved in a Bitmap with PixelFormat.Format24bppRgb. I wrote a simple class and test like below: </p>

<pre><code>public class CaptureScreenInfo
{
    public Bitmap TakeScreenShot(int posLeft, int posTop, int posRight, int posBottom)
    {
        int width = posRight - posLeft;
        int height = posBottom - posTop;

        Bitmap bmp = new Bitmap(width, height, PixelFormat.Format16bppGrayScale);

        using (Graphics gr = Graphics.FromImage(bmp))
        {
            gr.DrawImage(bmp, new Rectangle(0, 0, width, height));
        }

        return bmp;
    }
}
</code></pre>

<p>Unit Test: </p>

<pre><code>[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void RegularScreenShot()
    {
        CaptureScreenInfo csi = new CaptureScreenInfo();
        Bitmap bmp = csi.TakeScreenShot(0, 0, 800, 600);

        Assert.AreEqual(System.Drawing.Imaging.PixelFormat.Format24bppRgb, bmp.PixelFormat);
    }
}
</code></pre>

<p>The weird thing is that if I change the PixelFormat to something else then the desired Format24bppRgb, first test will ALWAYS pass and only on the second test (and every test after that) I will get a fail. Similary if I change back to Format24bppRgb, first test will fail, and next tests will pass. </p>

<p>Any idea why? </p>

<p><strong>EDIT</strong>: As per Luaan's comment I changed the code to be copy/paste-able. Obviously you will need to add all necessary references yourself. </p>