For me Handoko version works as well. That's surprising because pf32bit is supposed to mean 4 bytes, but matches 3 bytes RGB values.
The problem is that the PixelFormat property is not reliable. That's a bit why I wrote BGRABitmap library in the first place.
There are some surprising things about the pixel formats. It can be ARGB, BGRA or RGBA and you don't have much control over it. So you are better of leaving the PixelFormat to the default value (it is pfDevice but you don't need to set it) and detect what format you have:
function GetRandom32BitMap(aX, aY: integer): TBitMap;
var
bytesPerPixel, redOffset, greenOffset, blueOffset: byte;
LinePixs: PByte;
X, Y: integer;
color: TColor;
begin
Result := Tbitmap.Create;
Result.SetSize(aX, aY);
bytesPerPixel := Result.RawImage.Description.BitsPerPixel div 8;
redOffset := Result.RawImage.Description.RedShift div 8;
greenOffset := Result.RawImage.Description.GreenShift div 8;
blueOffset := Result.RawImage.Description.BlueShift div 8;
{$IFNDEF ENDIAN_LITTLE}
redOffset := bytesPerPixel - 1 - redOffset;
greenOffset := bytesPerPixel - 1 - greenOffset;
blueOffset := bytesPerPixel - 1 - blueOffset;
{$ENDIF}
color := TColor($00A5FF);
for Y := 0 to aY - 1 do
begin
LinePixs := Result.RawImage.GetLineStart(Y);
for X := 0 to aX - 1 do
begin
(LinePixs+blueOffset)^ := GetBValue(color);
(LinePixs+greenOffset)^ := GetGValue(color);
(LinePixs+redOffset)^ := GetRValue(color);
inc(LinePixs, bytesPerPixel);
end;
end;
end;