There is a sample code for saving BMP image format from the camera's SDK. This code is as follows. However, this process takes an average of 2-3 seconds.
//Click Save BMP button
procedure TForm1.SAVE_BMP_BUTTONClick(Sender: TObject);
begin
m_nSaveImageType := MV_Image_Bmp;
m_nRet := SaveImage();
if m_nRet<>MV_OK then
begin
ShowMessage( 'Save bmp fail.' + IntToHex(m_nRet,8) );
exit
end;
ShowMessage( 'Save bmp succeed.' );
end;
//Save Image
function TForm1.SaveImage(): Integer;
Var
nRecvBufSize: Cardinal;
stImageInfo: MV_FRAME_OUT_INFO_EX;
stParam: MV_SAVE_IMAGE_PARAM_EX;
chImageName: String; //ImageName
hFile: THandle; //handle of the imageFile
dwWriteLen: Cardinal; //Length that was written in the imageFile
begin
if not m_bStartGrabbing then
begin
Result := MV_E_CALLORDER;
exit
end;
//SaveImageType whether supported
if not ((MV_Image_Bmp=m_nSaveImageType) or (MV_Image_Jpeg=m_nSaveImageType)) then
begin
Result := MV_E_SUPPORT;
exit
end;
nRecvBufSize := 0;
if Nil = m_pBufForDriver then
begin
//Get size of one frame from camera
Result := GetIntValue(m_hDevHandle, 'PayloadSize', @nRecvBufSize);
if Result<>MV_OK then
begin
ShowMessage( 'failed in get PayloadSize.' + IntToHex(Result,8) );
exit
end;
m_nBufSizeForDriver := nRecvBufSize;
m_pBufForDriver := AnsiStrAlloc(m_nBufSizeForDriver);
if (Nil=m_pBufForDriver) or (not(StrBufSize(m_pBufForDriver)>0)) then
begin
ShowMessage( 'malloc m_pBufForDriver failed, run out of memory.' + IntToStr(m_nBufSizeForDriver) );
exit
end;
end;
//Start get one frame
ZeroMemory(@stImageInfo, sizeof(MV_FRAME_OUT_INFO_EX));
Result := MV_CC_GetOneFrameTimeout(m_hDevHandle^, m_pBufForDriver, m_nBufSizeForDriver, @stImageInfo, 1000);
if Result=MV_OK then
begin
if Nil = m_pBufForSaveImage then
begin
// en:BMP image size: width * height * 3 + 2048 (Reserved BMP header size)
m_nBufSizeForSaveImage := stImageInfo.nWidth * stImageInfo.nHeight * 3 + 2048;
m_pBufForSaveImage := AnsiStrAlloc(m_nBufSizeForSaveImage);
if (Nil=m_pBufForSaveImage) or (not(StrBufSize(m_pBufForSaveImage)>0)) then
begin
ShowMessage( 'malloc m_pBufForSaveImage failed, run out of memory.' + IntToStr(m_nBufSizeForSaveImage) );
exit
end;
end;
//Set camera parameter
ZeroMemory(@stParam, sizeof(MV_SAVE_IMAGE_PARAM_EX));
stParam.enImageType := m_nSaveImageType; //Image format to save
stParam.enPixelType := stImageInfo.enPixelType; //Camera pixel type
stParam.nWidth := stImageInfo.nWidth; //Width
stParam.nHeight := stImageInfo.nHeight; //Height
stParam.nDataLen := stImageInfo.nFrameLen;
stParam.pData := m_pBufForDriver;
stParam.pImageBuffer := m_pBufForSaveImage;
stParam.nBufferSize := m_nBufSizeForSaveImage; //Buffer node size
stParam.nJpgQuality := 80;
//jpg encoding, only valid when saving as Jpg. SDK ignore this parameter when saving as BMP
Result := MV_CC_SaveImageEx2(m_hDevHandle^, @stParam);
if Result<>MV_OK then exit;
//Save imageFile
if MV_Image_Bmp=stParam.enImageType then
begin
chImageName := FormatCName('%s%d%s%d%s%03d%s', 'Image_w', stImageInfo.nWidth, '_h', stImageInfo.nHeight, '_fn', stImageInfo.nFrameNum, '.bmp');
end
else if True then
begin
chImageName := FormatCName('%s%d%s%d%s%03d%s', 'Image_w', stImageInfo.nWidth, '_h', stImageInfo.nHeight, '_fn', stImageInfo.nFrameNum, '.jpg');
end
else
begin
Result := MV_E_SUPPORT;
end;
hFile:= CreateFileA(PAnsiChar(AnsiString(chImageName)), GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if hFile = 0 then exit;
WriteFile(hFile, m_pBufForSaveImage^, stParam.nImageLen, dwWriteLen, nil);
CloseHandle(hFile);
end;
Result := MV_OK;
end;
nsmuhendislik