1,184
社区成员
发帖
与我相关
我的任务
分享
void CDemoDlg::OnBnClickedBtnDetect()
{
int ret = 0;
unsigned char buffer[IDFP_IMG_WIDTH*IDFP_IMG_HEIGHT] = {0};
unsigned char bufferShow[IDFP_IMG_WIDTH*IDFP_IMG_HEIGHT] = {0};
LIVESCAN_BeginCapture(0);
// Timeout = 3000
if((ret = LIVESCAN_CaptureFPBmpData(0, buffer, 3000)) > 0)
{
for(int i = 0; i < IDFP_IMG_HEIGHT; i++)
{
memcpy(bufferShow+i*IDFP_IMG_WIDTH, buffer+(IDFP_IMG_HEIGHT-1-i)*IDFP_IMG_WIDTH, IDFP_IMG_WIDTH);
}
HBITMAP hb = BuildImage(bufferShow, IDFP_IMG_WIDTH, IDFP_IMG_HEIGHT);
GetDlgItem(IDC_STATIC_IMAGE)->SendMessage(STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hb);
DeleteObject(hb);
hb = NULL;
SetDlgItemText(IDC_EDT_INFO, "成功");
}
else
{
LIVESCAN_GetErrorInfo(ret, pszErrorInfo);
str.Format("失败, %s", pszErrorInfo);
SetDlgItemText(IDC_EDT_INFO, str);
}
LIVESCAN_EndCapture(0);
}
procedure TForm1.btn2Click(Sender: TObject);
var
ret, i: Integer;
buffer, bufferShow: PChar;
hb: HBITMAP;
begin
GetMem(buffer, IDFP_IMG_WIDTH * IDFP_IMG_HEIGHT);
GetMem(bufferShow, IDFP_IMG_WIDTH * IDFP_IMG_HEIGHT);
LIVESCAN_BeginCapture(0);
//timeout 3000;
ret := LIVESCAN_CaptureFPBmpData(0, buffer, 3000);
if ret > 0 then
begin
for i := 0 to IDFP_IMG_HEIGHT do
begin
CopyMemory(bufferShow + i * IDFP_IMG_WIDTH, buffer + (IDFP_IMG_HEIGHT - 1 - i) * IDFP_IMG_WIDTH, IDFP_IMG_WIDTH);
// memcpy(bufferShow+i*IDFP_IMG_WIDTH, buffer+(IDFP_IMG_HEIGHT-1-i)*IDFP_IMG_WIDTH, IDFP_IMG_WIDTH);
end;
hb := BuildImage(bufferShow, IDFP_IMG_WIDTH, IDFP_IMG_HEIGHT);
img1.Picture.Bitmap.Handle := hb;
// GetDlgItem(IDC_STATIC_IMAGE) - > SendMessage(STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hb);
DeleteObject(hb);
hb := NULL;
lst1.Items.Text := '成功';
end;
end;
HBITMAP BuildImage(BYTE *image, int width, int height)
{
static HBITMAP pic;
static CClientDC dc(NULL);
BYTE info[256 * 4 + 40], *colors;
BITMAPINFOHEADER *header = (BITMAPINFOHEADER*)info;
header -> biSize = 40;
header -> biHeight = height;
header -> biWidth = width;
header -> biPlanes = 1;
header -> biCompression = 0;
header -> biSizeImage = width * height;
header -> biXPelsPerMeter = 0;
header -> biYPelsPerMeter = 0;
header -> biClrImportant = 0;
header -> biBitCount = 8;
header -> biClrUsed = 256;
colors = info + 40;
for(int i = 0; i < 256; i++)
{
*colors++ = i;
*colors++ = i;
*colors++ = i;
*colors++ = 0;
}
if(pic)
DeleteObject(pic);
void *ptr;
// CClientDC dc(NULL);
pic = CreateDIBSection(dc.m_hDC, (BITMAPINFO*)info, DIB_RGB_COLORS, &ptr, NULL, 0);
memcpy(ptr, image, width * height);
return pic;
}
function BuildImage(image: PChar; width, height: Integer): HBITMAP; stdcall;
var
pic: HBITMAP;
DC: HDC;
info: array of PByte;
colors: PByte;
header: PBITMAPINFOHEADER;
begin
SetLength(info, 256 * 4 + 40);
header := Pointer(info);
header.biSize := 40;
header.biHeight := height;
header.biWidth := width;
header.biPlanes := 1;
header.biCompression := 0;
header.biSizeImage := width * height;
header.biXPelsPerMeter := 0;
header.biYPelsPerMeter := 0;
header.biClrImportant := 0;
header.biBitCount := 8;
header.biClrUsed := 256;
colors := Pointer(info + 40);//在这里报错了,不知道怎么转换colors = info + 40;C++这样写的。
// for i := 0 to 256 do//还有这下面怎么翻译呢?看不懂啊....
// begin
// *colors++ = i;
// *colors++ = i;
// *colors++ = i;
// *colors++ = 0;
// end;
// if (pic)
// DeleteObject(pic);
//
// void * ptr;
//// CClientDC dc(NULL);
// pic = CreateDIBSection(dc.m_hDC, (BITMAPINFO * )info, DIB_RGB_COLORS, &ptr, NULL, 0);
// memcpy(ptr, image, width * height);//一直到这里都看不懂了...
//
result := pic;
end;
function BuildImage(const image: PByte; width, height: Integer): HBITMAP;
var
i: Integer;
pic: HBITMAP;
dc: HDC;
ptr: Pointer;
info: array [0..(256 * 4 + 40) -1] of Byte;
header : PBitmapInfoHeader;
colors: PRGBQuad;
begin
header := @info[0];
header.biSize := 40;
header.biHeight := height;
header.biWidth := width;
header.biPlanes := 1;
header.biCompression := 0;
header.biSizeImage := width * height;
header.biXPelsPerMeter := 0;
header.biYPelsPerMeter := 0;
header.biClrImportant := 0;
header.biBitCount := 8;
header.biClrUsed := 256;
colors := @info[40];
for i := 0 to 256 - 1 do
begin
colors.rgbBlue := i;
colors.rgbGreen := i;
colors.rgbRed := i;
colors.rgbReserved := 0;
inc(colors);
end;
dc:= GetDC(0);
pic := CreateDIBSection(dc, PBITMAPINFO(@info[0])^, DIB_RGB_COLORS, ptr, 0, 0);
Move(image^, ptr^, width * height);
Result := pic;
end;