关于海康4000HC客户端进行抓图的实现 ( 积分: 100 )

  • 主题发起人 主题发起人 undead_bxg
  • 开始时间 开始时间
U

undead_bxg

Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个demo是关于海康4000HC客户端进行抓图的实现的,显示图像没有问题,但是运行
抓图时就出错了,不知道怎么回事,下面是我做的代码,希望各位指正谢谢。
unit unit1;

interface

uses Windows, SysUtils, Controls, Forms, Classes, ExtCtrls, StdCtrls, Dialogs, Graphics, jpeg;

type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
Panel1: TPanel;
Edit2: TEdit;
procedure Button2Click(Sender: TObject);
procedure SavePanelPicToFile(Panel: TPanel; FileName: string);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);

private { Private declarations } public { Public declarations }
end;

type
CapPicFunCallBack = procedure(StockHandle: longint; pBuf: PChar; nSize, nWidth,
nHeight, nStamp, nType, nReceaved: longint);


CLIENT_VIDEOINFO = record
m_bRemoteChannel: BYTE;
m_bSendMode: BYTE;
m_bRight: Boolean;
m_sIPAddress: PChar;
m_sUserName: PChar;
m_sUserPassword: PChar;
m_bUserCheck: Boolean;
m_hShowVide: THandle;
m_nImgFormat: BYTE;
end;
PCLIENT_VIDEOINFO = ^CLIENT_VIDEOINFO;

TReadDataCallBack = procedure(nport: DWORD; pPacketBuffer: PChar; nPacketSize: DWORD); stdcall;
const
T_UYVY = 1;
const
T_YV12 = 3;
const
T_RGB32 = 7;


function MP4_ClientStart(pClientinf: PCLIENT_VIDEOINFO; ReadDataCallBack: TReadDataCallBack): integer; stdcall; external 'hikclient.dll';
function MP4_ClientStop(StockHandle: integer): Boolean; stdcall; external 'hikclient.dll';
function MP4_ClientSetNetPort(dServerPort: WORD; dClientPort: WORD): Boolean; stdcall; external 'hikclient.dll';
function MP4_ClientGetServerChanNum(m_sIPAddress: PChar): WORD; stdcall; external 'hikclient.dll';
function MP4_ClientSetShowMode(dShowType: DWORD; colorKey: COLORREF): Boolean; stdcall; external 'hikclient.dll';
function MP4_ClientCleanup(): Boolean; stdcall; external 'hikclient.dll';
function MP4_ClientSetTTL(cTTLVal: BYTE): Boolean; stdcall; external 'hikclient.dll';
function MP4_ClientStartup(nMessage: Cardinal; hWnd: hWnd): Boolean; stdcall; external 'hikclient.dll';
function MP4_ClientSetBufferNum(StockHandle: longint; wBufNum: WORD): Boolean; stdcall; external 'hikclient.dll';
function MP4_ClientSetPlayDelay(StockHandle: longint; wBufNum: WORD): Boolean;
stdcall; external 'hikclient.dll';
function MP4_ClientSavePicFile(pBuf: PChar; nSize: longint; nWidth: longint; nHeight: longint; nType:longint; sFileName: PChar): Boolean; stdcall; external 'hikclient.dll';
function MP4_ClientSetCapPicCallBack(StockHandle: longint; CallBack:CapPicFunCallBack): Boolean; stdcall; external 'hikclient.dll';
var
Form1: TForm1;
id: integer;
t_infostr: CLIENT_VIDEOINFO;
implementation


{$R *.dfm}

procedure gatpic(StockHandle: longint; pBuf: PChar; nSize, nWidth,
nHeight, nStamp, nType, nReceaved: longint); //回调函数实现(CapPicFunCallBack)
begin //要停止这个函数指针要设为空,但要是调用就会出错
MP4_ClientSavePicFile(pBuf, nSize, nWidth, nHeight, T_YV12, 'd:/xyz.bmp');
end;
procedure TForm1.Button2Click(Sender: TObject); //把文件保存
var
pBuf: PChar;
nSize, nWidth, nHeight, nStamp, nType: longint;
sta: bool;
begin
SavePanelPicToFile(Panel1, 'bxg.bmp');
end;
procedure TForm1.SavePanelPicToFile(Panel: TPanel; FileName: string); //
//保存图片函数
var
img: TImage;
jp: TJpegImage;
begin
jp := TJpegImage.Create;
img := TImage.Create(nil);
img.Picture.Bitmap.Width := Panel1.Width;
img.Picture.Bitmap.Height := Panel1.Height;
bitblt(img.canvas.handle, 0, 0, Panel1.Width, Panel1.Height, getdc(Panel1.handle), 0, 0, srccopy);
try
with jp do
begin
jp.CompressionQuality := 90;
jp.Compress;
Assign(img.Picture.Bitmap);
SaveToFile('D:/zhy.jpg');
end;
finally
jp.Free;
end;
img.Free;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
MP4_ClientCleanup(); //停止图像发送
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
sta: Boolean;
gatpic:CapPicFunCallBack; //回调函数
sip: PChar;
begin
sip := PChar(Edit1.Text);
sta := false;
gatpic := nil; //
MP4_ClientSetNetPort(5050, 6050); //服务器端口,客户机端口
MP4_ClientStartup($0401, self.handle); //初始化视频
MP4_ClientSetShowMode(0, $FF00FF); //视频显示模式为0
MP4_ClientSetTTL(64);
t_infostr.m_nImgFormat := 0;
t_infostr.m_hShowVide := Panel1.handle;
t_infostr.m_bRemoteChannel := 0; //通道0
t_infostr.m_bSendMode := 0; //使用tcp/ip连接
t_infostr.m_sIPAddress := sip; //服务器ip地址
t_infostr.m_sUserName := '123'; //服务器用户名
t_infostr.m_sUserPassword := 'w';
t_infostr.m_bUserCheck := true;
id := MP4_ClientStart(@t_infostr, nil);
MP4_ClientSetBufferNum(id, 10); //设置缓冲
MP4_ClientSetPlayDelay(id, 30);
MP4_ClientSetCapPicCallBack(id, @gatpic); //
//问题出在这了,一调用这个一会程序就出错了,要是gatpic设成gatpic:=
//nil没有出错但是这个用来进行抓图的,不能不用,不知道在这出什么样的错了。
end;

end.


上面的代码是指在客户机上运行一个软件进行操作服务器,而视频采集卡是在服务器上的,客户机与服务器是用局域网连接起来的,运行到“MP4_ClientSavePicFile(pBuf, nSize, nWidth, nHeight, T_YV12, 'd:/xyz.bmp');”这句话就会出错,不知道怎么回事。
 
看看你的数据类型定义是否正确
 
应该是没有错了的呀,我看看.
 
试一试,在 interface 部分,定义gatpics
procedure gatpic(StockHandle: longint; pBuf: PChar; nSize, nWidth,
nHeight, nStamp, nType, nReceaved: longint); stdcall;
 
undead_bxg:
服务端网络的写法,能提供给我吗?
email:rzqcjwrz@163.com
 
后退
顶部