panel1上可以显示动态视频,但想在image1上用回调函数显示图片,但image1没任何反映。请文一下程序哪里出了问题??uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,VFW, IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient,Clipbrd,
StdCtrls, ExtCtrls; type
TForm1 = class(TForm)
Panel1: TPanel;
Button2: TButton;
IdUDPClient1: TIdUDPClient;
Button3: TButton;
Image1: TImage;
AviPanel: TPanel;
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
CapWnd:THandle; //定义捕捉窗句柄
CapParms:TcaptureParms; //用于设置设备属性的结构变量
BMPINFO:TBitmapInfo; //BMP图像信息
m_hCapWnd:Hwnd; implementation
function FrameCallBack(hWnd: HWND; lpVHdr: PVIDEOHDR) : LongInt;stdcall;
var hd:Thandle;
Bitmap:TBitmap;
begin //将数据显在Image1,
Bitmap:=TBitmap.Create;
Bitmap.Width :=BMPINFO.bmiHeader.biWidth;
// New size of Bitmap
Bitmap.Height:=BMPINFO.bmiHeader.biHeight;
hd:= DrawDibOpen;
DrawDibDraw(hd,Bitmap.canvas.handle,0,0,BMPINFO.BmiHeader.biwidth,BMPINFO.bmiheader.biheight,@BMPINFO.bmiHeader,lpVHdr^.lpData,0,0,BMPINFO.bmiHeader.biWidth,BMPINFO.bmiHeader.biheight,0);
DrawDibClose(hd);
Form1.image1.Picture.Bitmap.Assign(Bitmap) ;
Bitmap.SaveToFile('c:\dd.bmp');//这个保存的文件图片大小为0字节
showmessage('sss');//这句执行,说明回调函数执行了的
Bitmap.Free;
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
dwSize:Integer;
setBmp : BITMAPINFO ;
begin
try
m_hCapWnd:=capCreateCaptureWindow('',
WS_CHILD or WS_VISIBLE,0,0,AviPanel.width,AviPanel.height,AviPanel.Handle,0);
//avipanel 就是你要显示的视频窗口的;可以是form ,panel等
//AviPanel.width就是显示的宽度,AviPanel.height显示的高度; if(capDriverConnect(m_hCapWnd,0)) then
begin
// capOverlay(m_hCapWnd,true); //普通的摄像头不能用overlay的方式 主意;
capPreviewRate(m_hCapWnd,30); //设置帧率为30
capPreview(m_hCapWnd,true); // preview方式显示
dwSize:=capGetVideoFormatSize(m_hCapWnd);
capGetVideoFormat(m_hCapWnd,@setBmp, dwSize);
setBmp.bmiHeader.biWidth:=352; //这个就是设置你捕捉图片的大小了 宽度 :)
setBmp.bmiHeader.biHeight:=288; //这个就是设置你捕捉图片的大小了 高度 :)
capSetVideoFormat(m_hCapWnd,@setBmp,dwSize);
capSetCallbackOnFrame(m_hCapWnd,@FrameCallBack);
end;
except
end;
end; end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,VFW, IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient,Clipbrd,
StdCtrls, ExtCtrls; type
TForm1 = class(TForm)
Panel1: TPanel;
Button2: TButton;
IdUDPClient1: TIdUDPClient;
Button3: TButton;
Image1: TImage;
AviPanel: TPanel;
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
CapWnd:THandle; //定义捕捉窗句柄
CapParms:TcaptureParms; //用于设置设备属性的结构变量
BMPINFO:TBitmapInfo; //BMP图像信息
m_hCapWnd:Hwnd; implementation
function FrameCallBack(hWnd: HWND; lpVHdr: PVIDEOHDR) : LongInt;stdcall;
var hd:Thandle;
Bitmap:TBitmap;
begin //将数据显在Image1,
Bitmap:=TBitmap.Create;
Bitmap.Width :=BMPINFO.bmiHeader.biWidth;
// New size of Bitmap
Bitmap.Height:=BMPINFO.bmiHeader.biHeight;
hd:= DrawDibOpen;
DrawDibDraw(hd,Bitmap.canvas.handle,0,0,BMPINFO.BmiHeader.biwidth,BMPINFO.bmiheader.biheight,@BMPINFO.bmiHeader,lpVHdr^.lpData,0,0,BMPINFO.bmiHeader.biWidth,BMPINFO.bmiHeader.biheight,0);
DrawDibClose(hd);
Form1.image1.Picture.Bitmap.Assign(Bitmap) ;
Bitmap.SaveToFile('c:\dd.bmp');//这个保存的文件图片大小为0字节
showmessage('sss');//这句执行,说明回调函数执行了的
Bitmap.Free;
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
dwSize:Integer;
setBmp : BITMAPINFO ;
begin
try
m_hCapWnd:=capCreateCaptureWindow('',
WS_CHILD or WS_VISIBLE,0,0,AviPanel.width,AviPanel.height,AviPanel.Handle,0);
//avipanel 就是你要显示的视频窗口的;可以是form ,panel等
//AviPanel.width就是显示的宽度,AviPanel.height显示的高度; if(capDriverConnect(m_hCapWnd,0)) then
begin
// capOverlay(m_hCapWnd,true); //普通的摄像头不能用overlay的方式 主意;
capPreviewRate(m_hCapWnd,30); //设置帧率为30
capPreview(m_hCapWnd,true); // preview方式显示
dwSize:=capGetVideoFormatSize(m_hCapWnd);
capGetVideoFormat(m_hCapWnd,@setBmp, dwSize);
setBmp.bmiHeader.biWidth:=352; //这个就是设置你捕捉图片的大小了 宽度 :)
setBmp.bmiHeader.biHeight:=288; //这个就是设置你捕捉图片的大小了 高度 :)
capSetVideoFormat(m_hCapWnd,@setBmp,dwSize);
capSetCallbackOnFrame(m_hCapWnd,@FrameCallBack);
end;
except
end;
end; end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货