我正在尝试调整一些代码以适应Delphi:
https://github.com/cooljeanius/doublecmd/blob/master/src/platform/win/ugdiplus.pas
原始函数(我已经删除了不相关的代码):
{$mode objfpc}
// ...
function GetBitmapFromARGBPixels(graphics: GPGRAPHICS; pixels: LPBYTE; Width, Height: Integer): GPBITMAP;
var
pSrc, pDst: LPDWORD;
begin
// ...
pSrc := LPDWORD(pixels);
pDst := LPDWORD(bmData.Scan0);
// Pixels retrieved by GetDIBits are bottom-up, left-right.
for x := 0 to Width - 1 do
for y := 0 to Height - 1 do
pDst[(Height - 1 - y) * Width + x] := pSrc[y * Width + x];
GdipBitmapUnlockBits(Result, @bmData);
end;如何正确翻译这一行?(pSrc, pDst是LPDWORD):
pDst[(Height - 1 - y) * Width + x] := pSrc[y * Width + x];Delphi编译器显示错误:[Error] Unit1.pas(802): Array type required
我试过:
type
_LPDWORD = ^_DWORD;
_DWORD = array[0..0] of DWORD;
...
_LPDWORD(pDst)^[(Height - 1 - y) * Width + x] := _LPDWORD(pSrc)^[y * Width + x];我不确定这是否正确?
或者这个?
PByte(Cardinal(pDst) + (Height - 1 - y) * Width + x)^ := PByte(Cardinal(pSrc) + y * Width + x)^;发布于 2014-10-23 11:41:02
你可以这样做:
function GetBitmapFromARGBPixels(graphics: GPGRAPHICS; pixels: LPBYTE; Width, Height: Integer): GPBITMAP;
const
MaxArraySize = MaxInt div sizeof(DWord);
type
TLongDWordArray = array[0..pred(MaxArraySize)] of DWord;
PLongDWordArray = ^TLongDWordArray;
var
pSrc, pDst: PLongDWordArray;
begin
// ...发布于 2014-10-23 12:41:52
我认为在Delphi中解决这一问题的最简单方法是将编译配置为支持指针的索引:
{$POINTERMATH ON}一旦包含了这个指令,原始代码就会编译。
遗憾的是,Delphi7中没有这个选项。您需要声明一个指向DWORD数组的指针,并对其进行转换。
https://stackoverflow.com/questions/26526758
复制相似问题