gpt4 book ai didi

c# - 在Windows XP计算机上运行SlimDX C#应用程序时遇到的麻烦

转载 作者:行者123 更新时间:2023-12-03 08:01:40 26 4
gpt4 key购买 nike

我已经制作了一个简单的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
{
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)
{

}

}
}

当我在Windows 7 x64上运行此应用程序时,一切正常(在此处编译)

不幸的是,当我尝试在Windows XP x86计算机上运行此应用程序时-出现以下错误:

我如何解决它?
  • 在WinXP上安装了最新的DX
  • 在WinXP上安装了最新的SlimDX(此步骤解决了我之前的问题)
  • 在WinXP上安装了最新的.Net Framework v.4
  • 将此应用程序编译为x86并出于相同的原因使用SlimDX.dll x86
  • 我也将slimdx.dll放入dxcapture.exe(应用程序名称)所在的同一文件夹

  • 可能是什么问题? WinXP是否支持Directx9屏幕捕获?

    编辑:我试图注释掉不同的代码行,看来“设备创建”是问题所在。
                d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);

    WinXP机器集成了ATI图形,所以,我不知道..也许是问题所在,也许不是,但是我无法在其他PC上检查程序。

    最佳答案

    如您提交的错误报告中所述,问题似乎出在系统上,无论是缺少DirectX组件还是不支持Direct3D 9的图形适配器。如果您的卡至少不支持D3D9,您将无法使用SlimDX(或任何其他DirectX包装器)进行任何形式的渲染。

    关于c# - 在Windows XP计算机上运行SlimDX C#应用程序时遇到的麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9786003/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com