VideoForWindowsを使ってUSBカメラの映像をPanelに映しています。
この動画映像のサイズを拡大・縮小させたいのですが、方法がわかりません。
WinXPだとエクスプローラにUSBカメラがドライブのように表示され、これを開くと
エクスプローラ上で映像が見えます。
エクスプローラの大きさを変えるとリアルタイムでサイズが変わります。こんな感じで
できないでしょうか?
動的に変えるのが無理なら50%固定でも構いません。
よろしくお願いします。
//--------ソース
const
WM_CAP_START = WM_USER;
WM_CAP_DRIVER_CONNECT = WM_USER+10;
WM_CAP_DRIVER_DISCONNECT = WM_USER+11;
WM_CAP_SAVEDIB = WM_CAP_START + 25;
WM_CAP_SET_PREVIEW =WM_CAP_START+ 50 ;
WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52 ;
function capCreateCaptureWindow(lpszWindowName: PChar; dwStyle,x,y,nWidth,nHeight: Integer;
hWndParent: HWND; nID: Integer): HWND; stdcall; external 'avicap32.dll' name 'capCreateCaptureWindowA';
procedure TForm1.Button1Click(Sender: TObject);
begin
VideoHandle:= capCreateCaptureWindow ('Video',WS_VISIBLE or WS_CHILD,0,0, 640,480, Panel1.Handle,1);
if VideoHandle = 0 then begin
Exit;
end;
if SendMessage(VideoHandle,WM_CAP_DRIVER_CONNECT,0,0) = 0 then begin
DestroyWindow(VideoHandle);
VideoHandle:= 0;
Exit;
end;
//コネクト
SendMessage(VideoHandle,WM_CAP_DRIVER_CONNECT, 0,0) ;
//PREVIEW_RATE設定
SendMessage(VideoHandle,WM_CAP_SET_PREVIEWRATE,8,0);
//PREVIEW
SendMessage(VideoHandle,WM_CAP_SET_PREVIEW, 1,0);
Button1.Enabled:= False;
Button2.Enabled:= True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Button1.Enabled:= True;
Button2.Enabled:= False;
SendMessage(VideoHandle,WM_CAP_DRIVER_DISCONNECT,0,0);
DestroyWindow(VideoHandle);
VideoHandle:= 0;
end;
自己レスです。
const
WM_CAP_SET_SCALE=WM_CAP_START+ 53 ;
//-------------
var
w := Panel1.Width;
h := Panel1.Height;
VideoHandle:= capCreateCaptureWindow ('Video',WS_VISIBLE or WS_CHILD,0,0, w,h, Panel1.Handle,1);
//-------------
//サイズのフィッティング。PREVIEWの前に
SendMessage(VideoHandle, WM_CAP_SET_SCALE, 1, 0);
以上のように追加変更する事で出来ました。
お騒がせしました。
ツイート | ![]() |