Recent

Author Topic: Bitmap.Scanline  (Read 7435 times)

mbdev

  • New Member
  • *
  • Posts: 44
Bitmap.Scanline
« 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));     

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Bitmap.Scanline
« Reply #1 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...

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Bitmap.Scanline
« Reply #2 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.

mica

  • Full Member
  • ***
  • Posts: 196

mbdev

  • New Member
  • *
  • Posts: 44
Re: Bitmap.Scanline
« Reply #4 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.

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Bitmap.Scanline
« Reply #5 on: May 06, 2013, 05:00:28 pm »

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Bitmap.Scanline
« Reply #6 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.
Conscience is the debugger of the mind

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Bitmap.Scanline
« Reply #7 on: May 07, 2013, 05:32:33 pm »
Is that somehow different using TBitmap.RawImage.Data or TBGRABitmap.Data?

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Bitmap.Scanline
« Reply #8 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.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018