Sign in to follow this  
ucfchuck

[SlimDX] Bitmap from a Texture

Recommended Posts

i am trying to record video from the directx surface that i am rendering to, so i have it set up to create a texture2d buffer from the swapchain. but what i need is a bitmap to patch on the end of an avi file. currently i have to save each frame as a bitmap, then load each bitmap and then patch it on to the avi, which is needless to say horribly slow. i am recording at around 8 fps. i havent seen any direct conversion for a texture2d to a bitmap except for the Texture2d.tofile(). so ive been trying some other ways such as DXGI.SampleDescription sampleDescription = new DXGI.SampleDescription(); sampleDescription.Count = 1; sampleDescription.Quality = 0; Vdesc.Width = this.ClientRectangle.Width; Vdesc.Height = this.ClientRectangle.Height; Vdesc.MipLevels = Vdesc.ArraySize = 1; Vdesc.Format = DXGI.Format.R8G8B8A8_UNorm; Vdesc.SampleDescription = sampleDescription; Vdesc.Usage = D3D10.ResourceUsage.Default; Vdesc.BindFlags = D3D10.BindFlags.None; Vdesc.CpuAccessFlags = D3D10.CpuAccessFlags.None; backbuff = new SlimDX.Direct3D10.Texture2D(g_pd3dDevice, Vdesc); //later backbuff = g_pSwapChain.GetBuffer<D3D10.Texture2D>(0); DataRectangle mappedTex = backbuff.Map(0,D3D10.MapMode.Read, D3D10.MapFlags.None); Bitmap bitmap = new Bitmap(ClientRectangle.Width, ClientRectangle.Height); bitmap = Bitmap.FromResource(mappedTex.Data.DataPointer, "newbmp"); aviStream.AddFrame(bitmap); backbuff.Unmap(0); bitmap.Dispose(); The texture constructor will throw an error if the description allows cpu reads, or has anything set for the bindflags or usage. but i think its because the cpu is not allowed to read from the texture that the map operation returns an error. should i use a stream? or how can i get a texture into a bitmap?

Share this post


Link to post
Share on other sites
so after a while of reading slimdx, i find out there is a new release which has a Texture.ToStream() so i update and adapt the code a little and it compiles fine but now there is an issue with how my effect is loaded.

usercontrol.g_pEffect = D3D10.Effect.FromMemory(usercontrol.g_pd3dDevice, WPViewDX.Resources.Tutorial07, "fx_4_0", D3D10.ShaderFlags.EnableStrictness, D3D10.EffectFlags.None, null, null);



is no longer any good, it returns an SEHException:

An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in SlimDX.dll

Additional information: External component has thrown an exception.


even though this code worked on the last version of slimdx i had.

Share this post


Link to post
Share on other sites
VS has an in-process compiler it uses to hold on to some things for intellisense and various build-related magicks. It may have cached the reference to the old DLL in some fashion, and then use that old version with your newer assembly, which would eventually cause an unexpected error that could easily be recognized as a SEHException.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this