J
jingtao
Unregistered / Unconfirmed
GUEST, unregistred user!
以下语句先创建一个捕捉视频窗口.
procedure InitVideoCard;
begin
FillBitmapStruc;
CaptureHandle := capCreateCaptureWindow('Capture Window',
WS_VISIBLE or WS_CHILD,0,0,320,240,Application.MainForm.Handle, 1);
capDriverConnect(CaptureHandle, 0);
//set the video format
capSetVideoFormat(CaptureHandle, @BmpInfo, SizeOf(BmpInfo));
capPreviewRate(CaptureHandle, 40);
//capDlgVideoFormat(FCaptureHandle);
//capPreview(FCaptureHandle, True);
capSetCallbackOnFrame(CaptureHandle, @FrameCallBack);
end;
然后在回调函数里面处理数据
function FrameCallBack(hWnd: HWND;
lpVHdr: PVIDEOHDR): DWORD;
stdcall;
begin
// if ServerForm.ServerSocket1.Active then
Form1.CompareFrame(lpVHdr);
Result := DWORD(True);
end;
procedure TForm1.CompareFrame(lpVHdr: PVIDEOHDR);
var
BmpFileHeader:TBitmapFileHeader;
BmpInfoHeader:TBitmapInfoHeader;
MyMemoryStream:TMemoryStream;
MyBmp:TBitmap;
MyJpg:TJPEGImage;
begin
FillChar(BmpFileHeader,Sizeof(TBitmapfileheader),0);
FillChar(BmpInfoHeader,Sizeof(TBitmapinfoheader),0);
BmpFileHeader.bfType:=$4D42;//文件类型,必须为BM.
BmpFileHeader.bfSize:=BmpInfo.bmiHeader.biSizeImage;//BMP数据的大小字节
BmpFileHeader.bfReserved1:=0;//保留,必需为0
BmpFileHeader.bfReserved2:=0;//保留,必需为0
BmpFileHeader.bfOffBits:=Sizeof(TBitmapFileHeader)+Sizeof(TBitmapInfoHeader);//Specifies the offset, in bytes, from the BITMAPFILEHEADER structure to the bitmap bits.
My_GetUsbCamerBmpSize(BmpInfoHeader);
{
Panel1.Left:=0;
Panel1.Top:=0;
Panel1.ClientWidth:=BmpInfoHeader.biWidth;
Panel1.ClientHeight:=BmpInfoHeader.biHeight;
}
MyBmp:=TBitmap.Create;
MyJpg:=TJPEGImage.Create;
MyMemoryStream:=TMemoryStream.Create;
MyMemoryStream.Write(BmpFileHeader,sizeof(BmpFileHeader));
MyMemoryStream.Write(BmpInfoHeader,sizeof(BmpInfoHeader));
MyMemoryStream.Write(lpVHdr^.lpData^,BmpInfo.bmiHeader.biSizeImage);
MyMemoryStream.Position:=0;
MyBmp.LoadFromStream(MyMemoryStream);
ChangeBmp(MyBmp);
Image1.Picture.Bitmap.Assign(MyBmp);
MyJpg.Assign(MyBmp);
MyJpg.CompressionQuality := 65;
MyMemoryStream.Clear;
MyJpg.SaveToStream(MyMemoryStream);
MyMemoryStream.Position:=0;
SendUsbCamToClient('127.0.0.1',908,MyMemoryStream);
//Sendto(SocketVideo, MyMemoryStream.Memory^, MyMemoryStream.Size, 0, addr_toVideo, sizeof(addr_toVideo));
MyMemoryStream.Free;
MyBmp.Free;
MyJpg.Free;
//Memo1.Lines.Add(IntToStr(FInInfo.bmiHeader.biSizeImage));
//Close;
//FOutActSize := FInInfo.bmiHeader.biSizeImage;//获得视频信息图片的大小
end;
平时工作是正常的.现在的问题在于:如果主窗口最小化或者HIDE掉,就无法得到任何数据了,如何解决?
procedure InitVideoCard;
begin
FillBitmapStruc;
CaptureHandle := capCreateCaptureWindow('Capture Window',
WS_VISIBLE or WS_CHILD,0,0,320,240,Application.MainForm.Handle, 1);
capDriverConnect(CaptureHandle, 0);
//set the video format
capSetVideoFormat(CaptureHandle, @BmpInfo, SizeOf(BmpInfo));
capPreviewRate(CaptureHandle, 40);
//capDlgVideoFormat(FCaptureHandle);
//capPreview(FCaptureHandle, True);
capSetCallbackOnFrame(CaptureHandle, @FrameCallBack);
end;
然后在回调函数里面处理数据
function FrameCallBack(hWnd: HWND;
lpVHdr: PVIDEOHDR): DWORD;
stdcall;
begin
// if ServerForm.ServerSocket1.Active then
Form1.CompareFrame(lpVHdr);
Result := DWORD(True);
end;
procedure TForm1.CompareFrame(lpVHdr: PVIDEOHDR);
var
BmpFileHeader:TBitmapFileHeader;
BmpInfoHeader:TBitmapInfoHeader;
MyMemoryStream:TMemoryStream;
MyBmp:TBitmap;
MyJpg:TJPEGImage;
begin
FillChar(BmpFileHeader,Sizeof(TBitmapfileheader),0);
FillChar(BmpInfoHeader,Sizeof(TBitmapinfoheader),0);
BmpFileHeader.bfType:=$4D42;//文件类型,必须为BM.
BmpFileHeader.bfSize:=BmpInfo.bmiHeader.biSizeImage;//BMP数据的大小字节
BmpFileHeader.bfReserved1:=0;//保留,必需为0
BmpFileHeader.bfReserved2:=0;//保留,必需为0
BmpFileHeader.bfOffBits:=Sizeof(TBitmapFileHeader)+Sizeof(TBitmapInfoHeader);//Specifies the offset, in bytes, from the BITMAPFILEHEADER structure to the bitmap bits.
My_GetUsbCamerBmpSize(BmpInfoHeader);
{
Panel1.Left:=0;
Panel1.Top:=0;
Panel1.ClientWidth:=BmpInfoHeader.biWidth;
Panel1.ClientHeight:=BmpInfoHeader.biHeight;
}
MyBmp:=TBitmap.Create;
MyJpg:=TJPEGImage.Create;
MyMemoryStream:=TMemoryStream.Create;
MyMemoryStream.Write(BmpFileHeader,sizeof(BmpFileHeader));
MyMemoryStream.Write(BmpInfoHeader,sizeof(BmpInfoHeader));
MyMemoryStream.Write(lpVHdr^.lpData^,BmpInfo.bmiHeader.biSizeImage);
MyMemoryStream.Position:=0;
MyBmp.LoadFromStream(MyMemoryStream);
ChangeBmp(MyBmp);
Image1.Picture.Bitmap.Assign(MyBmp);
MyJpg.Assign(MyBmp);
MyJpg.CompressionQuality := 65;
MyMemoryStream.Clear;
MyJpg.SaveToStream(MyMemoryStream);
MyMemoryStream.Position:=0;
SendUsbCamToClient('127.0.0.1',908,MyMemoryStream);
//Sendto(SocketVideo, MyMemoryStream.Memory^, MyMemoryStream.Size, 0, addr_toVideo, sizeof(addr_toVideo));
MyMemoryStream.Free;
MyBmp.Free;
MyJpg.Free;
//Memo1.Lines.Add(IntToStr(FInInfo.bmiHeader.biSizeImage));
//Close;
//FOutActSize := FInInfo.bmiHeader.biSizeImage;//获得视频信息图片的大小
end;
平时工作是正常的.现在的问题在于:如果主窗口最小化或者HIDE掉,就无法得到任何数据了,如何解决?