Autor Beitrag
wolle87
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Do 11.02.10 15:11 
Hallo,

ist Api-Hooking die einzige Möglichkeit womit ich Screenshots von einer DirectX Anwendung machen kann oder gibt es da noch andere Möglichkeiten ? Ich habe bereits einen Code mit dem ich jedoch nur schwarze Bilder bekomme.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,Menus, ExtCtrls,
  //D3D10,D3DX10,DXGI,D3D10_1;
  DirectShow9, Direct3D9, D3DX9;

type
  TForm1 = class(TForm)
    Timer_Screenshot: TTimer;
    procedure Timer_ScreenshotTimer(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  protected
    procedure MakeScreenshot;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.MakeScreenshot;
var
  hr: HRESULT;
  pDDM: D3DDISPLAYMODE;
  pD3D: IDirect3D9;
  pD3DDevice: IDirect3DDevice9;
  d3dpp: TD3DPresentParameters;
  pSurface: IDirect3DSurface9;
  sFile: String;
  mGUID : TGUID;
begin
  pD3D := Direct3DCreate9(D3D_SDK_VERSION);

  pD3d.GetAdapterDisplayMode(D3DADAPTER_DEFAULT, pDDM);

  FillChar(d3dpp, SizeOf(d3dpp), 0);

  d3dpp.Windowed := True;
  d3dpp.Flags := D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
  d3dpp.BackBufferFormat := pDDM.Format;
  d3dpp.BackBufferHeight := pDDM.Height;
  d3dpp.BackBufferWidth := pDDM.Width;
  d3dpp.MultiSampleType := D3DMULTISAMPLE_NONE;
  d3dpp.SwapEffect := D3DSWAPEFFECT_DISCARD;
  d3dpp.hDeviceWindow := self.Handle;
  d3dpp.PresentationInterval := D3DPRESENT_INTERVAL_DEFAULT;
  d3dpp.FullScreen_RefreshRateInHz := D3DPRESENT_RATE_DEFAULT;

  hr := pD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, self.Handle,
                               D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                               @d3dpp, pd3dDevice);
  if FAILED(hr) then begin
    ShowMessage('pD3D.CreateDevice failed');
  end;

  hr := pD3DDevice.CreateOffscreenPlainSurface(pDDM.Width, pDDM.Height,
                D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, pSurface, nil);

  if FAILED(hr) then begin
    ShowMessage('pD3DDevice.CreateOffscreenPlainSurface failed');
  end;

  CreateGUID(mGUID);
  pD3DDevice.GetFrontBufferData(0, pSurface);
  sFile := '.\screenshot\' + GUIDToString(mGUID) + '.jpg';
  D3DXSaveSurfaceToFile(PAnsiChar(sFile), D3DXIFF_JPG, pSurface, nilnil);

  pSurface := nil;
  pD3DDevice := nil;
  pD3D := nil;


end;
[list=1][*]