0

我使用directx 9来构建模型。

我想将其保存为 bmp 文件。我找到了函数 D3DXSaveSurfaceToFile()

但我不知道如何在 C# 中使用它。

我该如何使用它?

4

1 回答 1

2

不幸的是,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
}
于 2013-01-25T05:04:16.920 回答