procedure TForm1.Button1Click(Sender: TObject);
var
r,g,b : byte ;
i,j,n:Integer;
Width,Height:Integer;
strTemp:string;
rArray,gArray,bArray: array of byte; //定义了3个数组,保存每个像素点的rgb值
SrcRGB: pRGBTriple;
bmp:TBitmap;
jpeg:TJPEGImage;
prarr,pgarr,pbarr:^Byte; //byte指针
begin
bmp:=Tbitmap.Create;
bmp.Assign(Image1.Picture.Graphic);
setLength(rArray,image1.Height*image1.Width-1);
setLength(gArray,image1.Height*image1.Width-1);
setLength(bArray,image1.Height*image1.Width-1);
Height:=image1.Height-1;
Width:=image1.Width-1;
showmessage('height '+inttostr(Height));
showMessage('width '+inttostr(Width));
try
for i:=0 to Height do
begin
SrcRGB := bmp.ScanLine[i];
n:=0;
for j:=0 to Width do //将rgb值保存到数组
begin
r:=SrcRGB.rgbtRed;
g:=srcrgb.rgbtGreen;
b:=srcrgb.rgbtBlue;
rArray[n]:=r;
gArray[n]:=g;
bArray[n]:=b;
n:=n+1;
end;
end;
////////////////////////
prarr:=@rArray;
pgarr:=@gArray;
pbarr:=@bArray;
ProcessWork.LoadRGB(prarr,pgarr,pbarr); //把保存rgb的3个数组传进去处理,这里要怎么把byte的数组按指针方式传入,loadRGB的定义在下面。
////////////////////////////
Image1.Picture.Bitmap.Assign(bmp);
finally
bmp.Free;
end;
end;
loadRGB定义TProcessWork是VC编写的ocx控件。
function TProcessWork.LoadRGB(var pcR: Byte; var pcG: Byte; var pcB: Byte): WordBool;如何把byte型的数组按照var pcR: Byte方式传入?
var
r,g,b : byte ;
i,j,n:Integer;
Width,Height:Integer;
strTemp:string;
rArray,gArray,bArray: array of byte; //定义了3个数组,保存每个像素点的rgb值
SrcRGB: pRGBTriple;
bmp:TBitmap;
jpeg:TJPEGImage;
prarr,pgarr,pbarr:^Byte; //byte指针
begin
bmp:=Tbitmap.Create;
bmp.Assign(Image1.Picture.Graphic);
setLength(rArray,image1.Height*image1.Width-1);
setLength(gArray,image1.Height*image1.Width-1);
setLength(bArray,image1.Height*image1.Width-1);
Height:=image1.Height-1;
Width:=image1.Width-1;
showmessage('height '+inttostr(Height));
showMessage('width '+inttostr(Width));
try
for i:=0 to Height do
begin
SrcRGB := bmp.ScanLine[i];
n:=0;
for j:=0 to Width do //将rgb值保存到数组
begin
r:=SrcRGB.rgbtRed;
g:=srcrgb.rgbtGreen;
b:=srcrgb.rgbtBlue;
rArray[n]:=r;
gArray[n]:=g;
bArray[n]:=b;
n:=n+1;
end;
end;
////////////////////////
prarr:=@rArray;
pgarr:=@gArray;
pbarr:=@bArray;
ProcessWork.LoadRGB(prarr,pgarr,pbarr); //把保存rgb的3个数组传进去处理,这里要怎么把byte的数组按指针方式传入,loadRGB的定义在下面。
////////////////////////////
Image1.Picture.Bitmap.Assign(bmp);
finally
bmp.Free;
end;
end;
loadRGB定义TProcessWork是VC编写的ocx控件。
function TProcessWork.LoadRGB(var pcR: Byte; var pcG: Byte; var pcB: Byte): WordBool;如何把byte型的数组按照var pcR: Byte方式传入?
#include "test.h"BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}void fnTest(char *buf)
{
MessageBox(0, buf, "", 0);
}在Delphi里面调用program Project1;{$APPTYPE CONSOLE}uses
SysUtils;//同一个函数的两种声明方式!
procedure fnTest1(var buf: Char); cdecl; external 'test.dll' name 'fnTest';
procedure fnTest2(buf: PChar); cdecl; external 'test.dll' name 'fnTest';var
c: array of Char;
begin
setlength(c, 20);
fillchar(c[0], length(c), 0);
strcopy(PChar(c), 'hello world!'); fnTest1(c[0]); fnTest2(PChar(c));
end.
按照fnTest2(PChar(c));方式写,编译的时候显示Types of actual and formal var parameters must be identical
function LoadRGB(var pcR: Byte; var pcG: Byte; var pcB: Byte): WordBool; dispid 9;c++定义:
int lodaRGB(byte* r, byte* g,byte*b){
}
setLength(gArray,image1.Height*image1.Width-1);
setLength(bArray,image1.Height*image1.Width-1);为什么要减1?不减!
stream: TMemoryStream;
bmpinfo: TBitmapInfo;
rArray,gArray,bArray: array of byte; //定义了3个数组,保存每个像素点的rgb值
begin
stream:=TMemoryStream.Create;
Image1.Picture.Bitmap.SaveToStream(stream);
stream.Position:=14;
stream.ReadBuffer(bmpinfo.bmiHeader, 40);
setLength(rArray,bmpinfo.bmiHeader.biHeight*bmpinfo.bmiHeader.biWidth);
setLength(gArray,bmpinfo.bmiHeader.biHeight*bmpinfo.bmiHeader.biWidth);
setLength(bArray,bmpinfo.bmiHeader.biHeight*bmpinfo.bmiHeader.biWidth);
Height:=bmpinfo.bmiHeader.biHeight-1;
Width:=bmpinfo.bmiHeader.biWidth-1;
.
.
.
stream.Free;
end;
width:=640;
height:=480;
还是出现cpu调试窗口