由DLL 中取得 image array,如何放進image裡? |
尚未結案
|
fengcheng
一般會員 發表:17 回覆:21 積分:7 註冊:2002-04-23 發送簡訊給我 |
由一個DLL 提供GetImage Function 如下:
GetImage()
Function Prototype:
BOOL GetImage( unsigned char *Image)
Parameters:
Image : An array for store the captured grayscale image. This array shell have the size 45312 bytes ( 192 X 236 ). Return Value:
• TRUE : Function call success.
• FALSE : Indicates an error. 我如何用這個function 在delphi 中顯示取得的圖形資料
|
TheMoon
中階會員 發表:17 回覆:95 積分:67 註冊:2002-06-05 發送簡訊給我 |
以下是將TBitmap的PixelFormat設為pf24bit的作法:
var i,j:Integer; Test:TBitmap; P:PByteArray; begin Test:=TBitMap.Create; Test.Width:=236; Test.Height:=192; Test.PixelFormat:=pf24bit; for j:=0 to H-1 do begin P:=Test.ScanLine[j]; for i:= 0 to W-1 do begin P[i*3]:=Image[j,i]; P[i*3 1]:=Image[j,i]; P[i*3 2]:=Image[j,i]; end; end; Image1.Canvas.Draw(0,0,Test); end;至於將TBitmap的PixelFormat設為pf8bit的作法, 需先設定其調色盤, 請參考: http://delphi.ktop.com.tw/topic.php?topic_id=46403 |
fengcheng
一般會員 發表:17 回覆:21 積分:7 註冊:2002-04-23 發送簡訊給我 |
TheMoon大:
感謝您的回答, 不過小弟我還是不甚了解..底下是對方給的demo範例中將array of char資料轉成圖形秀出來
此範例是VC的, 有些FUNCTION DELPHI沒有, 不知道該如何處理 void CDemoCHSDlg::ShowImg(void* ImgCur,int x, int y)
{
// TODO: Add your message handler code here and/or call default
// double scaleX;
// double scaleY;
// const SCALEX(argX) ((int) ((argX) * scaleX));
// const SCALEY(argY) ((int) ((argY) * scaleY)); CClientDC aDC(this);
::SetDIBitsToDevice(
aDC.m_hDC, // handle of device context
x, // x-coordinate of upper-left corner of dest. rect.
y, // y-coordinate of upper-left corner of dest. rect.
192, // source rectangle width
236, // source rectangle height
0, // x-coordinate of lower-left corner of source rect.
0, // y-coordinate of lower-left corner of source rect.
0, // first scan line in array
DibInfo->bmiHeader.biHeight, // number of scan lines
ImgCur, // address of array with DIB bits
DibInfo, // address of structure with bitmap info.
DIB_RGB_COLORS // RGB or palette indices
); } void CDemoCHSDlg::InitBMP()
{
//---------------------------------------------------------------------//
/*BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
RGBQUAD aColors[256];
BYTE aBitmapBits[90000];
*/
memset(&bmfh,0,sizeof(BITMAPFILEHEADER));
memset(&bmih,0,sizeof(BITMAPINFOHEADER));
bmfh.bfType='MB';
bmfh.bfSize=sizeof(BITMAPFILEHEADER)+192*236;
bmfh.bfReserved1=0;
bmfh.bfReserved2=0;
bmfh.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD);
bmih.biSize=40;
bmih.biWidth=192;
bmih.biHeight=236;
bmih.biPlanes=1;
bmih.biBitCount=8;
bmih.biCompression=0;
bmih.biSizeImage=0;
bmih.biXPelsPerMeter=0;
bmih.biYPelsPerMeter=0;
bmih.biClrUsed=0;
bmih.biClrImportant=0;
int cbHeaderSize=sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD);
DibInfo = (BITMAPINFO*) new char [ cbHeaderSize ];
DibInfo -> bmiHeader = bmih;
for(int i=0;i<256;i )
{
DibInfo -> bmiColors[i].rgbRed = i;
DibInfo -> bmiColors[i].rgbBlue = i;
DibInfo -> bmiColors[i].rgbGreen = i;
DibInfo -> bmiColors[i].rgbReserved = 0;
}
}
|
adonis
高階會員 發表:140 回覆:258 積分:159 註冊:2002-04-15 發送簡訊給我 |
|
fengcheng
一般會員 發表:17 回覆:21 積分:7 註冊:2002-04-23 發送簡訊給我 |
|
adonis
高階會員 發表:140 回覆:258 積分:159 註冊:2002-04-15 發送簡訊給我 |
|
TheMoon
中階會員 發表:17 回覆:95 積分:67 註冊:2002-06-05 發送簡訊給我 |
抱歉,程式修改如下:
var i,j:Integer; Test:TBitmap; P:PByteArray; begin Test:=TBitMap.Create; Test.Width:=236; Test.Height:=192; Test.PixelFormat:=pf24bit; for j:=0 to Test.Height-1 do begin P:=Test.ScanLine[j]; for i:= 0 to Test.Width-1 do begin P[i*3]:=Image[j*Test.Width i]; P[i*3 1]:=Image[j*Test.Width i]; P[i*3 2]:=Image[j*Test.Width i]; end; end; Image1.Canvas.Draw(0,0,Test); end;另外,試試看將你的陣列宣告成 Array[0..XX] of Byte |
TheMoon
中階會員 發表:17 回覆:95 積分:67 註冊:2002-06-05 發送簡訊給我 |
我後來想到了,
如果你是用Array of Char讀入Image,
那原來的程式改成:
for j:=0 to Test.Height-1 do begin P:=Test.ScanLine[j]; for i:= 0 to Test.Width-1 do begin P[i*3]:=Ord(Image[j*Test.Width i]); P[i*3 1]:=Ord(Image[j*Test.Width i]); P[i*3 2]:=Ord(Image[j*Test.Width i]); end; end;這樣應該就可以解決了 |
fengcheng
一般會員 發表:17 回覆:21 積分:7 註冊:2002-04-23 發送簡訊給我 |
終於可以了, 把成功的程式碼pos上來 function GetImage( Image: PUCHAR): BOOL; stdcall; implementation {$R *.dfm} function GetImage; external HWCtrlCHSdll name 'GetImage'; procedure TForm1.Timer1Timer(Sender: TObject);
var
hFlash: HWND;
Image: array[0..IMG_WIDTH*IMG_HIGHT] of UCHAR;
i,j:Integer;
Test:TBitmap;
P:PByteArray; begin GetImage( @Image); Test:=TBitMap.Create;
Test.Width:=192;
Test.Height:=236;
Test.PixelFormat:=pf24bit; try
for j:=0 to Test.Height-1 do
begin
P:=Test.ScanLine[j];
for i:= 0 to Test.Width-1 do
begin
P[i*3]:=Image[j*Test.Width i];
P[i*3 1]:=Image[j*Test.Width i];
P[i*3 2]:=Image[j*Test.Width i];
end;
end;
except
end; Image1.Canvas.Draw(0,0,Test);
Test.Free;
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |