我在天敏卡sdk3000 delphi api DEMO中的一个视频回调函数中实现一个功能,就是能取出每帖的图片并显示在image控件中。这样由于视频回调函数是实时的,所以,理论上运行后除了浏览窗口的实时画面还应该在image中看到实时显示的画面,可是我不知道如何在视频回调函数(PrcCapSourceStream)中取出每帖图片送到image上。
视频回调函数声明如下://允许视频原始回调格式
function VCAEnableCapSourceStream(nCards: Integer; bCapStream: VCBOOL;
enVideoFieldType: VideoFieldType; pCapStream: TPrcCapSourceStream)
: HRESULT; stdcall; external DLL_SDK3000;
// 捕获原始流回调
TPrcCapSourceStream = procedure (nCardID: Integer; pBuf: PByte; nWidth: Integer; nHeight: Integer; nBitCount: Integer);stdcall;
我在它的demo中加了一个button,在它的单击事件里写到:
procedure TForm1.Button4Click(Sender: TObject);
begin
VCAEnableCapSourceStream(g_nCard,ToVcbool(true),Interlaced_Field,Addr(MyPrcCapSourceStream)) ;//允许视频回调
end;而后又在视频回调函数里写到:
procedure MyPrcCapSourceStream (nCardID: Integer; pBuf: PByte; nWidth: Integer; nHeight: Integer; nBitCount: Integer);stdcall;
begin
//这里我试了,有视频的时候是实时触发的事件,不过我不知道该怎么写,把参数里的缓冲区的内容送到image中显示。end;
视频回调函数声明如下://允许视频原始回调格式
function VCAEnableCapSourceStream(nCards: Integer; bCapStream: VCBOOL;
enVideoFieldType: VideoFieldType; pCapStream: TPrcCapSourceStream)
: HRESULT; stdcall; external DLL_SDK3000;
// 捕获原始流回调
TPrcCapSourceStream = procedure (nCardID: Integer; pBuf: PByte; nWidth: Integer; nHeight: Integer; nBitCount: Integer);stdcall;
我在它的demo中加了一个button,在它的单击事件里写到:
procedure TForm1.Button4Click(Sender: TObject);
begin
VCAEnableCapSourceStream(g_nCard,ToVcbool(true),Interlaced_Field,Addr(MyPrcCapSourceStream)) ;//允许视频回调
end;而后又在视频回调函数里写到:
procedure MyPrcCapSourceStream (nCardID: Integer; pBuf: PByte; nWidth: Integer; nHeight: Integer; nBitCount: Integer);stdcall;
begin
//这里我试了,有视频的时候是实时触发的事件,不过我不知道该怎么写,把参数里的缓冲区的内容送到image中显示。end;
bmpinfo: TBitmapInfo;
buf: pointer;
begin
//设置图像格式
bmpinfo.bmiHeader.biSize := sizeof(BITMAPINFOHEADER);
bmpinfo.bmiHeader.biWidth := 176;
bmpinfo.bmiHeader.biHeight := 144;
bmpinfo.bmiHeader.biPlanes := 1;
bmpinfo.bmiHeader.biBitCount := 24;
bmpinfo.bmiHeader.biSizeImage := bmiHeader.biWidth*bmiHeader.biHeight*3;
Image1.Canvas.Lock;//防止闪烁
try
Image1.Picture.Bitmap.Handle:=CreateDIBSection(0, bmpinfo, DIB_RGB_COLORS, buf, 0, 0);
if buf <> nil then
Move(videobuf, buf^, bmpinfo.bmiHeader.biSizeImage);
finally
Image1.Canvas.Unlock;
end;
end;
bmpinfo.bmiHeader.biWidth := nWidth;
bmpinfo.bmiHeader.biHeight := nHeight;
bmpinfo.bmiHeader.biPlanes := 1;
bmpinfo.bmiHeader.biBitCount := nBitCount;
bmpinfo.bmiHeader.biSizeImage := bmiHeader.biWidth*bmiHeader.biHeight*3; Move(pBuf^, buf^, bmpinfo.bmiHeader.biSizeImage);
bmpinfo.bmiHeader.biWidth * bmpinfo.bmiHeader.biHeight * (bmpinfo.bmiHeader.biBitCount div 8)
bmpinfo.bmiHeader.biSizeImage :=
bmpinfo.bmiHeader.biWidth * bmpinfo.bmiHeader.biHeight * (bmpinfo.bmiHeader.biBitCount div 8)
谢谢你的帮助,代码对我很有用处。
你的代码现在可以在回调函数中通过,不过运行后,在image中还是没有看到画面,不知道是为什么?能再次帮忙给看一下吗?
if buf <> nil then
Move(pBuf^, buf^, bmpinfo.bmiHeader.biSizeImage);
中buf = nil 所以 没有走下面的代码。请问是为什么,难道是它上面的那句代码有问题。
FillChar(bmpinfo, sizeof(bmpinfo), 0);
我的qq:9076629