在Windows XP计算机上运行SlimDX C#应用程序时遇到的问题
我制作了一个简单的C#WinForms应用程序,它可以制作屏幕截图在Windows XP计算机上运行SlimDX C#应用程序时遇到的问题,c#,windows,winforms,error-handling,slimdx,C#,Windows,Winforms,Error Handling,Slimdx,我制作了一个简单的C#WinForms应用程序,它可以制作屏幕截图 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using SlimDX.Direct3D9; using SlimDX; namespace KMPP { public class DxScreenCapture {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SlimDX.Direct3D9;
using SlimDX;
namespace KMPP
{
public class DxScreenCapture
{
Device d;
public DxScreenCapture()
{
PresentParameters present_params = new PresentParameters();
present_params.Windowed = true;
present_params.SwapEffect = SwapEffect.Discard;
d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
}
public Surface CaptureScreen()
{
Surface s = Surface.CreateOffscreenPlain(d, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Format.A8R8G8B8, Pool.Scratch);
d.GetFrontBufferData(0, s);
return s;
}
}
}
现在我们来谈谈:
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using SlimDX.Direct3D9;
using SlimDX;
using KMPP;
using System.Diagnostics;
using System.Threading;
namespace dxcapture
{
public partial class Form1 : Form
{
DxScreenCapture sc = new DxScreenCapture();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Stopwatch stopwatch = new Stopwatch();
DateTime current = DateTime.Now;
string n = string.Format(@"text-{0:yyyy-MM-dd_hh-mm-ss-tt}.bmp",DateTime.Now);
string directory = (@"C:\temp\");
string name = (".bmp");
string filename = String.Format("{0:hh-mm-ss}{1}", DateTime.Now, name);
string path = Path.Combine(directory, filename);
stopwatch.Start();
Thread.Sleep(1000);
Surface s = sc.CaptureScreen();
Surface.ToFile(s, path, ImageFileFormat.Bmp);
stopwatch.Stop();
s.Dispose();
textBox1.Text = ("Elapsed:" + stopwatch.Elapsed.TotalMilliseconds);
}
private void button2_Click(object sender, EventArgs e)
{
}
}
}
当我在Windows7x64上运行这个应用程序时,一切都正常(它是在这里编译的)
不幸的是,当我尝试在Windows XP x86机器上运行此应用程序时,我遇到以下错误:
我是如何修复它的?
- 在WinXP上安装了最新的DX
- 在WinXP上安装了最新的SlimDX(顺便说一句,此步骤解决了我以前的问题)
- 在WinXP上安装了最新的.Net Framework v.4
- 出于同样的原因,将此应用编译为x86并使用SlimDX.dll x86
- 我还将slimdx.dll放入dxcapture.exe(应用程序名)所在的同一文件夹中
d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
WinXP机器集成了ATI图形,所以我不知道。。也许这就是问题所在,也许不是,但我无法在其他电脑上检查我的程序。如您提交的错误报告中所述,问题似乎出在您的系统上,无论是缺少DirectX组件还是您的图形适配器不支持Direct3D 9。如果您的卡至少不支持D3D9,您将无法使用SlimDX(或任何其他DirectX包装器)进行任何类型的渲染