【问题标题】:troubles with running SlimDX C# application on Windows XP machine在 Windows XP 机器上运行 SlimDX C# 应用程序的问题
【发布时间】:2012-03-20 11:36:14
【问题描述】:

我制作了一个简单的 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 显卡,所以,我不知道.. 可能是这个问题,也可能不是,但我无法在其他电脑上检查我的程序。

【问题讨论】:

    标签: c# windows winforms error-handling slimdx


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-03-03
      • 2011-11-28
      • 1970-01-01
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      • 2017-02-20
      相关资源
      最近更新 更多