Autor Beitrag
Phil511
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Do 15.05.08 22:05 
Hi,

Ich suche einen weg das Ich Bilder von meiner Webcam auslese und wenn ich einen Button drücke das Bild abspeichere.

Nun nach Suche im Forum hab einen Quelltext gefunden mit dem Ich das Bild meiner Webcam in einen Panel anzeigen kann.

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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;
const
  WM_CAP_DRIVER_CONNECT = WM_USER + 10;
  WM_CAP_EDIT_COPY = WM_USER + 30;
  WM_CAP_SET_PREVIEW = WM_USER + 50;
  WM_CAP_SET_OVERLAY = WM_USER + 51;
  WM_CAP_SET_PREVIEWRATE = WM_USER + 52;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//Dann brauchst du noch das hier
function capCreateCaptureWindow(lpszWindowName: LPCSTR;
  dwStyle: DWORD;
  x, y,
  nWidth,
  nHeight: integer;
  hwndParent: HWND;
  nID: integer): HWND; stdcall;
  external 'AVICAP32.DLL' name 'capCreateCaptureWindowA';

procedure TForm1.Button1Click(Sender: TObject);
var handle:THandle;
begin
   handle := capCreateCaptureWindow('Video',ws_child+ws_visible, 0,
  0320240, Panel1.Handle, 1); //Wie du siehst, brauchst du ein Panel in diesem Beispiel ;-)
  SendMessage(handle, WM_CAP_DRIVER_CONNECT, 00);
  SendMessage(handle, WM_CAP_SET_PREVIEWRATE, 300);
  sendMessage(handle, WM_CAP_SET_OVERLAY, 10);
  SendMessage(handle, wm_cap_set_preview, 10);
end;

end.


Ich habe denn Quelltext hier im Forum gefunden, weiß aber leider nicht was da genau vor sich geht könnte vlt irgendwer ein paar Worte dazu sagen. Wäre nett.

Aber meine nächste Frage wäre wie ich da aktuelle Bild abspeichern kann.
Bitte auch hier wenn irgendwer nen Quelltext postet bitte mit ein paar Kommentaren versehen das ich das auch verstehe was da vorsich geht.

Danke im Vorraus.

mfg.Philipp

Moderiert von user profile iconUGrohne: Quote- durch Delphi-Tags ersetzt
chrisdrury
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 184

WinXP
D5 Prof
BeitragVerfasst: Fr 16.05.08 07:17 
Schau Dir mal diesen Thread an:
www.delphipraxis.net...ilder+speichern.html :wink:
Phil511 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Fr 16.05.08 14:03 
Zuerst einmal Danke.

Das Problem jedoch ist das sich das Programm starten lässt, wenn ich jedoch speichert er das Bild nicht!

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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;
const
  WM_CAP_DRIVER_CONNECT = WM_USER + 10;
  WM_CAP_EDIT_COPY = WM_USER + 30;
  WM_CAP_SET_PREVIEW = WM_USER + 50;
  WM_CAP_SET_OVERLAY = WM_USER + 51;
  WM_CAP_SET_PREVIEWRATE = WM_USER + 52;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    function SaveWebcamPictureDIB(pFileName: PChar;WebcamHandle: THandle):Boolean;
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//Dann brauchst du noch das hier
function capCreateCaptureWindow(lpszWindowName: LPCSTR;
  dwStyle: DWORD;
  x, y,
  nWidth,
  nHeight: integer;
  hwndParent: HWND;
  nID: integer): HWND; stdcall;
  external 'AVICAP32.DLL' name 'capCreateCaptureWindowA';

procedure TForm1.Button1Click(Sender: TObject);
var handle:THandle;
begin
   handle := capCreateCaptureWindow('Video',ws_child+ws_visible, 0,
  0320240, Panel1.Handle, 1); //Wie du siehst, brauchst du ein Panel in diesem Beispiel ;-)
  SendMessage(handle, WM_CAP_DRIVER_CONNECT, 00);
  SendMessage(handle, WM_CAP_SET_PREVIEWRATE, 300);
  sendMessage(handle, WM_CAP_SET_OVERLAY, 10);
  SendMessage(handle, wm_cap_set_preview, 10);
end;

function Tform1.SaveWebcamPictureDIB(pFileName: PChar;WebcamHandle: THandle):Boolean;
const WM_CAP_FILE_SAVEDIB = WM_USER + 25;
begin
if IsWindow(WebcamHandle) then
  result := (SendMessage(WebcamHandle,WM_CAP_FILE_SAVEDIB,0,LPARAM(pFileName)) <> 0)
else
  result := false;
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
//VideoHandle = Zurückgegebenes Handle bei der Initialisierung
SaveWebcamPictureDIB(PChar('C:\test.jpg'),Panel1.Handle);  
// Hier habe ich statt VideoHandel Panel1.Handle geschreiben wahrscheinlich stimmt das nicht so ganz!!! 
end;

end.