请教:C++代码转换成Delphi(视频处理)ULONG m_ulSampleDone;
int m_ulRGBMax;
ULONG* pSamplePicture;
m_ulRGBMax =0;
ULONG VideoLine,VideoCol;
ULONG VideoMode;
SFCG_GetVideoMode( VideoMode, m_uCardNum );
if( VideoMode )
{
VideoLine =720;
VideoCol =576;
}
else
{
VideoLine =720;
VideoCol =488;
}
m_str.Format(_T(" "));
m_StartEndTime_str.Format(_T(" "));
m_SpendTime_str.Format(_T(" "));
pSamplePicture =new ULONG[VideoLine*VideoCol]; //Sampled data
if( !SFCG_SetVideoSample(m_uCardNum) )
{
MessageBox( _T("Set video sample error!"),_T("Error") );
return;
}
while( !SFCG_GetIfVideoSampleDone( m_ulSampleDone, m_uCardNum ) );
SFCG_GetVideoSampleData( pSamplePicture, m_uCardNum );
CClientDC dc(this);
if (m_hBitmap)
::DeleteObject(m_hBitmap);
//成员变量位图句柄,用于在视图重绘时
m_hBitmap =::CreateCompatibleBitmap(dc.GetSafeHdc(),VideoLine,VideoCol);
if(!m_hBitmap) //生成句柄不成功
return;
CBitmap bmp;
bmp.Attach(m_hBitmap);
BITMAP bm;
unsigned int PixelBytes =0;
unsigned int i;
bmp.GetBitmap(&bm);
BYTE* lpBits =NULL;
BYTE r,g,b;
switch(bm.bmBitsPixel)
{
case 16: // R:G:B =5:6:5
PixelBytes =2;
lpBits =new BYTE[bm.bmWidth*bm.bmHeight*PixelBytes];
for(i =0;i <VideoCol*VideoLine;i++)
{
r =BYTE(pSamplePicture[i]>>16); //Get Red Component
g =BYTE(pSamplePicture[i]>>8); //Get Green Component
b =BYTE(pSamplePicture[i]); //Get Blue Component
lpBits[2*i] =(0xe0&(g < <3)) ¦(b>>3);
lpBits[2*i+1] =(r&0xf8) ¦(g>>5);
}
break;
case 24:
PixelBytes =3; // R:G:B =8:8:8
lpBits =new BYTE[bm.bmWidth*bm.bmHeight*PixelBytes];
for(i =0;i <VideoCol*VideoLine;i++)
{
r =BYTE(pSamplePicture[i]>>16); //Get Red Component
g =BYTE(pSamplePicture[i]>>8); //Get Green Component
b =BYTE(pSamplePicture[i]); //Get Blue Component
lpBits[3*i] =b;
lpBits[3*i+1] =g;
lpBits[3*i+2] =r;
}
break;
default:
break;
}
if(lpBits) // Not 32 bits true color
bmp.SetBitmapBits(bm.bmWidth*bm.bmHeight*PixelBytes,lpBits);
else // 32 bits true color
bmp.SetBitmapBits(VideoCol*VideoLine*4,pSamplePicture);
// Display sampled picture
CDC mem;
mem.CreateCompatibleDC(&dc);
CBitmap* pOld =mem.SelectObject(&bmp);
dc.BitBlt(0,0,VideoLine,VideoCol,&mem,0,0,SRCCOPY);
mem.SelectObject(pOld);
mem.DeleteDC();
bmp.Detach();
if(lpBits)delete lpBits;
delete pSamplePicture;--
太长了,清明起来试一试---
该回复于2008-04-06 20:36:02被IT快活林站长彻底删除---
2楼的,卖您妈B不?---
一般视频采集卡有 delphi 接口的---
const m_ulRGBMax =0;
var
m_ulSampleDone:Longword;
m_ulRGBMax:integer;
pSamplePicture:^longword;
VideoLine,VideoCol:Longword;
VideoMode:Longword;
SamplePicture:array [0..VideoLine*VideoCol-1] of Longword; //Sampled data 如果很大的情况,可能堆栈溢出,您可以自己改成他原来哪种动态创建就行了
SFCG_GetVideoMode( VideoMode, m_uCardNum );
if( VideoMode <>0 ) then
bgein
VideoLine :=720;
VideoCol :=576;
end else
begin
VideoLine :=720;
VideoCol :=488;
end;
m_str:='';//这里要注意,delphi的string和vc的CString是不一样的,要注意处理
m_StartEndTime_str:='';
m_SpendTime_str:='';
pSamplePicture:=@(SamplePicture[0]);//Sampled data
if(not SFCG_SetVideoSample(m_uCardNum)) then//要看您函数返回是否bool型,不然的话应该写成 if(SFCG_SetVideoSample(m_uCardNum)=0) then
begin
application.MessageBox('Set video sample error!','Error',mb_iconError+mb_ok);
exit;
end;
while( not SFCG_GetIfVideoSampleDone( m_ulSampleDone, m_uCardNum ) ) do//同上,应该注意函数返回是否bool型
begin
SFCG_GetVideoSampleData( pSamplePicture, m_uCardNum );
end;
//............下面的作图部分今天[{$WriteTime}]没时间回答您了,您可以自己查查资料,不是很复杂,或者是我空了再给您翻译了,呵呵
---
还有点时间,作图部分也给您翻译几句先!
var
dc : HDC;
bmp : TBitmap;
m_hBitmap : HBitMap;
lpBits : pbyte;
r,g,b : byte;
PixelBytes,i : Cardinal;
dc:=GetDC(Form1.handle);//这里面的handle就是您显示窗口的handle,您用pannel等也一样
if (m_hBitmap <>0) then DeleteObject(m_hBitmap);//这句您自己看是否有必要,如果前面m_hBitmap没创建过就不用这句
//成员变量 位图句柄,用于在视图重绘时
m_hBitmap :=CreateCompatibleBitmap(dc,VideoLine,VideoCol);
if(m_hBitmap=nil) then exit; //生成句柄不成功
bmp.Handle:=m_hBitmap;
PixelBytes =0;
case bmp.Pixelformat of
{
pf16bit: // R:G:B =5:6:5
begin
PixelBytes :=2;
lpBits :=GetMemory(bmp.Width*bmp.Height*PixelBytes];
for i:=0 to VideoCol*VideoLine-1 do
begin
r :=BYTE(pSamplePicture[i] shl 16); //Get Red Component
g :=BYTE(pSamplePicture[i] shl 8); //Get Green Component
b :=BYTE(pSamplePicture[i]); //Get Blue Component
lpBits[2*i] :=($E0 and(g shr 3))or(b shl 3);
lpBits[2*i+1] :=(r and $f8)or(g shl 5);
end;
end;
pf24bit:
begin
//...........这就自己看这办
end;
end;
if (lpBits <>nil) then // Not 32 bits true color
//这里什么都不做
else // 32 bits true color
bmp.PixelFormat:=pf32bit;
// Display sampled picture
下面的是创建计算机内存位图然后bitblt到屏幕或者是位图
然后释放创建的相关资源,如位图,HDC等,您自己应该可以搞定了我就不写了,这下真没时间了
---
谢谢大家的帮忙,非常受益了!---
问题搞定了,一直忘了帖上来与大家一起分享,处理得有一点笨,希望大家给点建议!
//获取视频的制式,VideoMode为1时,工作(Work)在PAL制,为0时,工作(Work)在NTSC制
SFCG_GetVideoMode(@VideoMode, m_uCardNum - 1);
if Boolean(VideoMode) then
begin
VideoLine :=720;
VideoCol :=576;
end
else
begin
VideoLine :=720;
VideoCol :=488;
end;
bmp :=TBitmap.Create;
bmp.PixelFormat :=pf24Bit;
bmp.width :=VideoLine;
bmp.Height :=VideoCol;
i :=VideoLine * VideoCol;
GetMem(pSamplePicture, i * 4);
if not SFCG_SetVideoSample(m_uCardNum - 1) then //设置板卡进入采样状态
begin
Application.MessageBox('板卡图像采样错误!', '提示', MB_Ok + MB_ICONINFORMATION);
Exit;
end;
{SFCG_GetIfVideoSampleDone获取采样是否完成, true采样完成, false采样未完成
如果采样未完成,程序(Procedures)(Procedures)将始终在此循环直到采样完成}
while true do
begin
if SFCG_GetIfVideoSampleDone(@m_ulSampleDone, m_uCardNum - 1) then
Break;
end;
{SFCG_GetVideoSampleData得到采样数据(Data),得到的是图像中每个像素点的ARGB格式的采样数据(Data),
高位为A,依次是R,G,B
对PAL制信号,采样的有效行为576行,每行的有效点为720点}
SFCG_GetVideoSampleData(pSamplePicture, m_uCardNum - 1);
{读取每个像素点的RGB值,并按缓存中的排列依次排列在控件}
for j :=0 to i - 1 do
begin
R :=Byte(((pULONG(DWORD(pSamplePicture) + j * 4)^) shr 16) and $FF);
G :=Byte(((pULONG(DWORD(pSamplePicture) + j * 4)^) shr 8) and $FF);
B :=Byte(pULONG(DWORD(pSamplePicture) + j * 4)^ and $FF);
if j <=719 then
begin
Row :=j;
Col :=0;
end
else
begin
Row :=j mod 720;
Col :=j div 720;
end;
bmp.Canvas.Pixels[Row, Col] :=RGB(R, G, B);
Application.ProcessMessages;
end;
Image1.Picture.Bitmap.Assign(bmp);
Image1.Repaint;
Bmp.Free;
FreeMem(pSamplePicture, i * 4);---
绝大部分的都是很好的建议! 值得学习---
我也想了解,谢谢LZ.