簡體   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