Jump to content
  • Advertisement
Sign in to follow this  
Khaos Dragon

get Image from direct3D texture in c#

This topic is 4844 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

Does anyone know how you could extract a System.Drawing.Image from a Direct3D.Texture in realtime in c#? I can think of saving the direct3D texture to a temp file and then loading the image from the file but if there were a more direct approach I would prefer that.

Share this post


Link to post
Share on other sites
Advertisement
You can get a Graphics (GDI) interface from a Surface and I imagine that with that you can use the standard GDI functions to copy it to another Image. It's probably not something you'd want to do every frame for performance reasons, but it has to beat saving and reloading. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by DrunkenHyena
You can get a Graphics (GDI) interface from a Surface and I imagine that with that you can use the standard GDI functions to copy it to another Image. It's probably not something you'd want to do every frame for performance reasons, but it has to beat saving and reloading. :)


I am a little confused, let's say I have a direct3d texture called tex. I see I can do the following which gives me a Graphics object tex.GetSurfaceLevel(0).GetGraphics() but I don't see anything useful I can do with it.

Share this post


Link to post
Share on other sites
Hmm, you're right. I was sure that getting a DC would actually let you do something useful with it. That's disappointing. Sorry about that.

Your best bet is probably to lock the surface and copy the bits to an Image manually. If they're both 32-bit XRGB values then it should be pretty easy.

Share this post


Link to post
Share on other sites
Gentlemen, Gentlemen. Much easier way to do it.

Bitmap image;

using (GraphicsStream stream = TextureLoader.SaveToStream(ImageFileFormat.Bmp, texture))
{
image = new Bitmap(stream);
}

Hope that helps you out :) Glad I saw this post. I am working on a control as we speak that uses this functionality. Feel free to check it out in my developer journal in a few minutes when I post a screenshot :)


~Graham

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!