繁体   English   中英

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

[英]troubles with running SlimDX C# application on Windows XP machine

我已经制作了一个简单的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计算机上运行此应用程序时-出现以下错误:

http://i.minus.com/ipilqHeWqbvKe.png

我如何解决它?

  • 在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包装器)进行任何形式的渲染。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM