您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> .NET >> directx截图的问题

directx截图的问题

来源:网络整理     时间:2016/6/7 20:22:00     关键词:directx

关于网友提出的“directx截图的问题”问题疑问,本网通过在网上对“directx截图的问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题:directx截图的问题
描述:

怎么我GetBackBuffer截出来的图是花的
private void button1_Click(object sender, EventArgs e)
        {
            Microsoft.DirectX.Direct3D.Device myDevice;
           PresentParameters presentParams = new PresentParameters();
            presentParams.Windowed = true;
            presentParams.AutoDepthStencilFormat = DepthFormat.D16;
          presentParams.SwapEffect = SwapEffect.Discard;
            presentParams.PresentFlag = PresentFlag.LockableBackBuffer;
          presentParams.BackBufferWidth = 1280;
           presentParams.BackBufferHeight = 800;
            presentParams.MultiSample = MultiSampleType.None;
          presentParams.BackBufferCount = 1;
            presentParams.DeviceWindowHandle = this.Handle;
            
               
                myDevice = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
              
                Surface mySurface = myDevice.GetBackBuffer(0, 0, Microsoft.DirectX.Direct3D.BackBufferType.Mono);
                SurfaceLoader.Save("c:\\Screenshot.bmp", ImageFileFormat.Bmp, mySurface);
                    Microsoft.DirectX.GraphicsStream gStr = Microsoft.DirectX.Direct3D.SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, mySurface);
                    pictureBox1.Image = Bitmap.FromStream(gStr);
                    Bitmap screen = new Bitmap(Bitmap.FromStream(gStr));
                    gStr.Dispose();
                    mySurface.Dispose();
                }


解决方案1:


            PresentParameters pp = new PresentParameters();
            pp.Windowed = true;
            pp.SwapEffect = SwapEffect.Discard;
            Device dv = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, pp);
            Surface sf = dv.CreateOffscreenPlainSurface(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Format.A8R8G8B8, Pool.SystemMemory);
            dv.GetFrontBufferData(0, sf);
            GraphicsStream gs = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, sf);
            pictureBox1.Image = Bitmap.FromStream(gs);

以上介绍了“directx截图的问题”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/1584495.html

相关图片

相关文章