呵呵,又该我得分了:)
以下代码中的关键部分也是别人给我的,不知道会不会侵权
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Video,
Vfw;
type
TForm1 = class(TForm)
VideoCap1: TVideoCap;
Image1: TImage;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure VideoCap1VideoStream(sender: TObject;
lpVhdr: PVIDEOHDR);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
info: PBitmapInfo;
procedure TForm1.Button1Click(Sender: TObject);
begin
with VideoCap1do
begin
DriverIndex := 0;
VideoPreview := true;
PreviewScaleToWindow := true;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
VideoCap1.GetBitmapInfo(Pointer(info));
Image1.Picture.Bitmap.Width := info.bmiHeader.biWidth;
Image1.Picture.Bitmap.Height := info.bmiHeader.biHeight;
VideoCap1.OnFrameCallback := VideoCap1VideoStream;
end;
procedure FrameToBitmap(Bitmap: TBitmap;
FrameBuffer: pointer;
BitmapInfo: TBitmapInfo);
begin
if bitmapInfo.bmiHeader.BiCompression = bi_RGB then
with Bitmapdo
setDiBits(canvas.handle, handle, 0, BitmapInfo.bmiHeader.biheight,
FrameBuffer, BitmapInfo, DIB_RGB_COLORS);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
VideoCap1.OnFrameCallback := nil;
end;
procedure TForm1.VideoCap1VideoStream(sender: TObject;
lpVhdr: PVIDEOHDR);
begin
FrameToBitmap(Image1.Picture.Bitmap, lpvhdr^.lpData, info^);
Image1.Invalidate;
end;
end.