成功的時候還是比較多的,就是在捕獲圖象不定時報錯invalid pointer operation,然后直接閃退程式
//捕獲的間隔時間幾乎1秒1次
代碼如下:
procedure TmainForm.SampleGrabber1Buffer(Sender: TObject;
SampleTime: Double; pBuffer: Pointer; BufferLen: Integer);
var
tmpBmp: TBitmap;
tmpBmp2: TBitmap;
jpg: TJPEGImage;
timeStr: string;
fileName: string;
JpgFile: TFileStream;
dir: string;
begin
if bmp1isLock then begin
cardTimer.Enabled := False;//讀卡定時器
ProgLog.ErrorLogToFile(True, 'SampleGrabber1Buffer', '開始保存圖片!');
bmp1isLock := False;
jpg := TJPEGImage.Create;
try
tmpBmp2 := TBitmap.Create;
if SampleGrabber1.GetBitmap(tmpBmp2, pBuffer, BufferLen) then
begin
timeStr := FormatDateTime('yyyy-MM-dd hh:mm:ss', Now);
cam1Bmp.Assign(tmpBmp2);//cam1Bmp攝像頭捕獲到的TBitmap圖象
cam1Bmp.Canvas.TextOut(10, 10, timeStr);
end;
jpg.Assign(cam1Bmp);
TimeLbl.Caption := timeStr;
jpg.CompressionQuality := 65; //jpg壓縮質量
jpg.JPEGNeeded; //壓縮
fileName := getFileName() + recID;
dir := CapDir + 'snapshot\' + FormatDateTime('yyyyMMdd', Now) + '\';
if not DirectoryExists(dir) then ForceDirectories(dir); //創建圖片目錄
if FileExists(CapDir + 'snapshot\' + fileName + '.jpg') then fileName := '9' + fileName; //檔案名存在
JpgFile := TFileStream.Create(dir + fileName + '.jpg', fmCreate); //打開檔案流
JpgFile.Position := 0;
jpg.SaveToStream(JpgFile);//圖片保存到檔案夾
snapImg.Picture.Assign(jpg);// snapImg圖片控制元件顯示出來
//呼叫存盤程序保存到資料庫
StreamPic := TMemoryStream.Create; // 創建記憶體流
jpg.SaveToStream(StreamPic);
if (cardNo <> '') then begin
dbResult := DBConnfrm.addCardRecord(ADOStoredProc2, CardID, cardNo, strName, timeStr, fileName) + ' #';
end;
bmp1isLock := False; //cam1Bmp鎖定標志
FREEANDNIL(StreamPic);
FREEANDNIL(JpgFile);
FREEANDNIL(jpg);
FREEANDNIL(tmpBmp2);
except
on E: Exception do
begin
ProgLog.ErrorLogToFile(True, 'getPictureClick', ('保存影像例外!' + E.message));
if (jpg <> nil) then FREEANDNIL(jpg);
if (JpgFile <> nil) then FREEANDNIL(JpgFile);
if (tmpBmp2 <> nil) then FREEANDNIL(tmpBmp2);
if (tmpBmp <> nil) then FREEANDNIL(tmpBmp);
end;
end;
cardTimer.Enabled := True;
end;
end;
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
沒人嗎!!!!uj5u.com熱心網友回復:
有沒有用TVideoWindow打開預覽?如果有,下面的方式可以抓到圖片
fstream := TMemoryStream.Create;
VideoWindow.VMRGetBitmap(fstream);
fstream.SaveToFile(FShootFile);
fstream.Free;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/122321.html
標籤:語言基礎/算法/系統設計
