日期:2014-05-17  浏览次数:21124 次

directx截图的问题
怎么我GetBackBuffer截出来的图是花的
[code=C#][/code]
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();
  }

------解决方案--------------------
C# code

            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);