Jump to content
  • Advertisement
Sign in to follow this  
DrGUI

[.net] Bitmap from Direct3D.Surface

This topic is 4732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I hope you had a great christmas! I get my backbuffer screenshot like this:
Direct3D.Surface scrShot = Device.GetBackBuffer(0, 0, BackBufferType.Mono);
Now, I used to save this to a file but now I want to get it to a System.Drawing.Bitmap. How do you do this? You can get the Graphics of the surface, but surprisingly I can't find any way to get this to a Bitmap! I would have thought that you should be able to save a Graphics to a bitmap or save it to disk in some way. Cheers and Happy New Year! Andrew

Share this post


Link to post
Share on other sites
Advertisement
This should do it:


using(Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono))
{
SurfaceLoader.Save("someScreenShot.jpg", ImageFileFormat.Jpg, backbuffer);
}

Share this post


Link to post
Share on other sites
Thanks Rob, but I already save the image to disk.

Now I want to get it into a System.Drawing.Bitmap so I can manipulate it first, which is what I'm having trouble with.

I could save it to a bitmap in the temp directory and load it again, but that's just messy and slow.

Share this post


Link to post
Share on other sites
This (or something like it) should work:
using(Surface surface=device.GetBackBuffer(0, 0, BackBufferType.Mono)) {
using(Stream stream=SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, surface)) {
Bitmap bitmap=new Bitmap(stream);
}
}

Share this post


Link to post
Share on other sites
Cheers! You rock!

I would have expected an overload for SurfaceLoader.Save to take a stream as parameter really, rather than having another function.

Your use of the using keyword is also much better than my try...finally.

Happy New Year!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!