Lazarus
Programming => Graphics and Multimedia => Graphics => Topic started by: mbdev on May 05, 2013, 02:23:28 pm
-
Hello,
Could you help me translate this lines from Delphi to Lazarus?
Bitmap.Width := FWidth;
Bitmap.Height := FHeight;
Bitmap.PixelFormat := pf32bit;
CopyMemory(Bitmap.Scanline[Bitmap.Height - 1], @FBitmap[0], FWidth * FHeight * SizeOf(TRGBQUAD));
-
For a full functionality you can try BGRA controls, BGRABitmap:
http://wiki.freepascal.org/BGRAControls
Regards
p.s. I'm not sure but I think Image32 also...
-
You can do that through RawImage aswell, if you don't want to rely on 3rd party libraries.
TRGBQUAD = record
rgbBlue : BYTE;
rgbGreen : BYTE;
rgbRed : BYTE;
rgbReserved : BYTE;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var b1, b2: TBitmap; data1, data2: PByte;
begin
b1:=TBitmap.Create;
b2:=TBitmap.Create;
b1.PixelFormat:=pf32bit;
b2.PixelFormat:=pf32bit;
b1.SetSize(100, 100);
b2.SetSize(100, 100);
b1.Canvas.Font.Color:=clRed;
b1.Canvas.TextOut(10, 10, 'Test');
data1:=b1.RawImage.Data;
data2:=b2.RawImage.Data;
move(data1^, data2^,
b1.Width * b1.Height * SizeOf(TRGBQUAD));
// This here would be perfect but it doesn't compile..
// so i had to pass them through data1, data2 variables instead.
//move(b1.RawImage.Data^, b2.RawImage.Data^,
// b1.Width * b1.Height * SizeOf(TRGBQUAD));
b1.Free;
b2.SaveToFile('c:\test.bmp');
b2.Free;
end;
This code here made me a test.bmp with red 'Test' written in it.
-
graphic32 can help to
http://graphics32.org/documentation/Docs/Units/GR32/Classes/TCustomBitmap32/Properties/ScanLine.htm
-
Hi,
I tried this
[...]
private
....
FBitmap: array of TRGBQUAD;
procedure TPathTracer.Acquire(Bitmap: TBGRABitmap);
begin
Bitmap.SetSize(Fwidth,fheight);
CopyMemory(Bitmap.ScanLine[Bitmap.Height - 1], @FBitmap[0], FWidth * FHeight * SizeOf(TRGBQUAD));
end;
but I wouldn't do the same :/
Moreover I didn't found Scanline in the TCustomBitmap32.
-
http://wiki.freepascal.org/BGRABitmap_tutorial_4
-
@mbdev:
If you want to copy all data, you must use the Data property. If you use Scanline, you must copy each line separately. This is because the line order is not the same depending on the operating system.
If you want to copy all Data at once, and that you need to have lines in a specific order, you can check the LineOrder property, and apply VerticalSwap if needed.
-
Is that somehow different using TBitmap.RawImage.Data or TBGRABitmap.Data?
-
It can be because TBGRABitmap.Data is always 32-bit BGRA, hence the name of the library. Whereas with a TBitmap, the format can change depending on the image or on the operating system.