C代码
// 读像素点
BYTE yPixel = *(pBase + pTable[nCol].XEntry + pTable[nRow].YEntry);
// 处理像素点
yPixel = 255 – yPixel; // invert it
//写像素点
*(pBase + pTable[nCol].XEntry +pTable[nRow].YEntry) = yPixel;
是直接从个内存地址读出个点,处理后,再写回地址中
// 读像素点
BYTE yPixel = *(pBase + pTable[nCol].XEntry + pTable[nRow].YEntry);
// 处理像素点
yPixel = 255 – yPixel; // invert it
//写像素点
*(pBase + pTable[nCol].XEntry +pTable[nRow].YEntry) = yPixel;
是直接从个内存地址读出个点,处理后,再写回地址中
var
yPixel:Byte;
begin
yPixel:=PByte(pBase+pTable[nCol]XEntry+pTable[nrow].YEntry)^;
yPixel:=255-yPixel;
PByte(pBase + pTable[nCol].XEntry +pTable[nRow].YEntry)^:=yPixel;
IImageVPA = interface(IUnknown)
['{616D4949-6567-5056-4120-202020202020}']
function Dimensions(var pBands: Integer; var pWidth: Integer; var pHeight: Integer): HResult; stdcall;
function DataType(lIndex: Integer; var pDataType: Integer): HResult; stdcall;
function VPA(lIndex: Integer; hBase: PPPrivateAlias1; hVPA: PPUserType1): HResult; stdcall;
function GetCoords(var pCoordinateMap: TCoordinateMap): HResult; stdcall;
function SetCoords(cmCoordinateMap: TCoordinateMap): HResult; stdcall;
end; VPAEntry = packed record
XEntry: Integer;
YEntry: Integer;
end; PPPrivateAlias1 = ^Pointer; {*}
PUserType1 = ^VPAEntry; {*}
PPUserType1 = ^PUserType1; {*}以下是C处理代码IImageVPA* im = (IImageVPA *)ImageDevice1->GetActiveImage();
long lBands,lWidth,lHeight;
im->Dimensions(&lBands,&lWidth,&lHeight);
long lDataType;
im->DataType(0,&lDataType);
if (lDataType==8)
{
// unsigned byte data in the image
long nBand;
for(nBand=0; nBand < lBands; nBand++)
{
// set up per band pixel access
BYTE* pBase;
VPAEntry* pTable;
im->VPA(nBand, (void **)&pBase,&pTable);
long nRow,nCol;
for(nRow=0; nRow < lHeight; nRow++)
for(nCol=0; nCol < lWidth; nCol++)
{
// read pixel
BYTE yPixel = *(pBase + pTable[nCol].XEntry + pTable[nRow].YEntry);
// process pixel
yPixel = 255 – yPixel; // invert it
//write pixel
*(pBase + pTable[nCol].XEntry + pTable[nRow].YEntry) = yPixel;
} // end columns
} // end bands
} // end unsigned byte data
im->Release(); // MUST release when done怎么转换为Delphi代码???
var
pBase:PByte;
pTable:Array of VPAEntry;
...
begin
.........
SetLength(pTable,nBand);
.........
im^.VPA(nBand,pointer(@pBase),&pTable[0]);
............. yPixel:=PByte(integer(pBase)+pTable[nCol].XEntry+pTable[nrow].YEntry)^;
yPixel:=255-yPixel;
PByte(integer(pBase) + pTable[nCol].XEntry +pTable[nRow].YEntry)^:=yPixel;
protected
...
function Get_ActiveImage: IImageVPA;
...
public
...
property ActiveImage: IImageVPA read Get_ActiveImage;
...
end; function TImageDevice.Get_ActiveImage: IImageVPA;
begin
Result := DefaultInterface.ActiveImage;
end;
这是说明书上的一个例子,但是C写的,我想用delphi写.实际的应用要简单些,就是把图象的数据写到ImageDevice的图象缓冲区中.上面的例子就是对缓冲区的操作
var
im: IImageVPA;
begin
im := ImageDevice1.ActiveImage;
...
end;