Eric J.
Eric J.

Reputation: 150118

Screen Capture in PNG Format Works, but not BMP Format

I'm using the code below to capture the screen with a game running

public static Bitmap CaptureScreen()
{
    DxScreenCapture cap = new DxScreenCapture();
    var surface = cap.CaptureScreen();

    Bitmap png;
    using (DataStream stream = Surface.ToStream(surface, ImageFileFormat.Bmp))
    {
        png = new Bitmap(stream);
        png.Save(@"C:\Temp\MyFile.bmp");
    }

    return png;
}

When saving as ImageFileFormat.Bmp, the saved file is entirely black. If I change the format to ImageFileFormat.Png (and the file extension to .png), the image saves just fine.

Why can I save in PNG format, but not in BMP format?

Upvotes: 0

Views: 373

Answers (1)

Thomas Ayoub
Thomas Ayoub

Reputation: 29441

This code should work (see the complete enum):

png.Save(@"C:\Temp\MyFile.bmp", ImageFormat.Bmp)

Upvotes: 1

Related Questions