根据数组中数据的方向,您可能需要通过以下方式更改方向: pscanLine32[j].rgbReserved := Arr[i * Width + Height - j].A;
type
TPixel = packed record
B: Byte;
G: Byte;
R: Byte;
A: Byte;
end;
TMyBitmapData = array of TPixel;
type
pRGBQuadArray = ^TRGBQuadArray;
TRGBQuadArray = ARRAY [0 .. $EFFFFFF] OF TRGBQuad;
Procedure FillBitMap(var bmp: TBitMap; Arr: TMyBitmapData; Width, Height: Integer);
var
pscanLine32: pRGBQuadArray;
i, j: Integer;
begin
if not Assigned(bmp) then
bmp := TBitMap.Create;
bmp.PixelFormat := pf32Bit;
bmp.ignorepalette := true;
bmp.Width := Width;
bmp.Height := Height;
for i := 0 to bmp.Height - 1 do
begin
pscanLine32 := bmp.Scanline[i];
for j := 0 to bmp.Width - 1 do
begin
pscanLine32[j].rgbReserved := Arr[i * Width + j].A;
pscanLine32[j].rgbBlue := Arr[i * Width + j].B;
pscanLine32[j].rgbRed := Arr[i * Width + j].R;
pscanLine32[j].rgbGreen := Arr[i * Width + j].G;
end;
end;
end;
procedure TForm4.Button1Click(Sender: TObject);
var
MyBitmapWidth: Integer;
MyBitmapHeight: Integer;
Size: Cardinal;
MyBitmapData: TMyBitmapData;
bmp: TBitMap;
x: Integer;
begin
MyBitmapWidth := 100;
MyBitmapHeight := 100;
Size := MyBitmapWidth * MyBitmapHeight;
SetLength(MyBitmapData, Size );
for x := 0 to MyBitmapWidth - 1 do
begin
MyBitmapData[x * MyBitmapWidth + x].A := 255;
MyBitmapData[x * MyBitmapWidth + x].R := 255;
end;
bmp := TBitMap.Create;
try
FillBitMap(bmp, MyBitmapData, MyBitmapWidth,MyBitmapHeight );
Image1.picture.Assign(bmp);
finally
bmp.Free;
end;
end;