Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: mbdev on May 05, 2013, 02:23:28 pm

Title: Bitmap.Scanline
Post by: mbdev on May 05, 2013, 02:23:28 pm
Hello,
Could you help me translate this lines from Delphi to Lazarus?

Code: [Select]
Bitmap.Width := FWidth;
 Bitmap.Height := FHeight;
 Bitmap.PixelFormat := pf32bit;

 CopyMemory(Bitmap.Scanline[Bitmap.Height - 1], @FBitmap[0], FWidth * FHeight * SizeOf(TRGBQUAD));     
Title: Re: Bitmap.Scanline
Post by: exdatis on May 05, 2013, 03:34:40 pm
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...
Title: Re: Bitmap.Scanline
Post by: User137 on May 05, 2013, 04:35:39 pm
You can do that through RawImage aswell, if you don't want to rely on 3rd party libraries.
Code: [Select]
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.
Title: Re: Bitmap.Scanline
Post by: mica on May 05, 2013, 06:30:05 pm
graphic32 can help to
http://graphics32.org/documentation/Docs/Units/GR32/Classes/TCustomBitmap32/Properties/ScanLine.htm
Title: Re: Bitmap.Scanline
Post by: mbdev on May 06, 2013, 03:56:57 pm
Hi,

I tried this
Code: [Select]
[...]
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.
Title: Re: Bitmap.Scanline
Post by: exdatis on May 06, 2013, 05:00:28 pm
http://wiki.freepascal.org/BGRABitmap_tutorial_4
Title: Re: Bitmap.Scanline
Post by: circular on May 07, 2013, 02:11:27 pm
@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.
Title: Re: Bitmap.Scanline
Post by: User137 on May 07, 2013, 05:32:33 pm
Is that somehow different using TBitmap.RawImage.Data or TBGRABitmap.Data?
Title: Re: Bitmap.Scanline
Post by: circular on May 18, 2013, 05:17:57 pm
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.
TinyPortal © 2005-2018