我使用directx 9來構建模型。如何在C#中使用函數D3DXSaveSurfaceToFile()
我想將它保存到bmp文件。我發現函數D3DXSaveSurfaceToFile()
但我不知道如何在C#中使用它。
我該如何使用它?
我使用directx 9來構建模型。如何在C#中使用函數D3DXSaveSurfaceToFile()
我想將它保存到bmp文件。我發現函數D3DXSaveSurfaceToFile()
但我不知道如何在C#中使用它。
我該如何使用它?
不幸的是,在c#中沒有這樣的功能。 請嘗試以下代碼:
try
{
// initialize D3D device
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
Device myDevice = new
Device(0,DeviceType.Hardware,this,CreateFlags.SoftwareVertexProcessing,presentParams);
// create a surface the size of screen,
// format had to be A8R8G8B8, as the GetFrontBufferData returns
// only memory pool types allowed are Pool.Scratch or Pool.System memory
Surface mySurface =
myDevice.CreateOffscreenPlainSurface(SystemInformation.PrimaryMonitorSize.Width,SystemInformation.PrimaryMonitorSize.Height,Format.A8R8G8B8,Pool.SystemMemory);
//Get the front buffer.
myDevice.GetFrontBufferData(0,mySurface);
//saves surface to file
SurfaceLoader.Save("surface.bmp",ImageFileFormat.Bmp,mySurface);
}
catch
{
//whatever
}
感謝您的幫助。但是我怎麼才能讓表面不是像這樣的整個屏幕 – user1369825
你不能。你唯一的選擇是從完整的截圖中刪除所需的部分。 – Flot2011
我可以旋轉模型並將其創建爲avi文件嗎? – user1369825
至少請發佈函數。如果我們看不到代碼,我們無法幫助您。 –