Recent

Author Topic: duplicate tbitmap how?  (Read 2105 times)

Josh

  • Hero Member
  • *****
  • Posts: 930
duplicate tbitmap how?
« on: January 10, 2022, 05:43:10 pm »
Hi

Apologies my brain is having a non working day :)

How do i duplicate tbitmaps ie bitmap1:=bitmap2 .

I can create the bitmap1, then i can assign it to timage  to make sure it works.

i need to then copy the bitmap1 to bitmap2, and then modify bitmap 2.

i have tried using bitmap2.canvas.copyrect(rect(0,0,width,height),bitmap1,rect(...))
but this does not duplicate the contents,
if i assign bitmap2 to timage2, it is empty.

Any ideas?

its to create a fixed bitmap (bitmap1); which then gets updated/changed in bitmap2 to update a timage, like a buffer
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

winni

  • Hero Member
  • *****
  • Posts: 3045
Re: duplicate tbitmap how?
« Reply #1 on: January 10, 2022, 08:10:33 pm »
Hi!

Very simple, step by step:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormClick(Sender: TObject);
  2. var bmp1,bmp2 : TBitmap;
  3. R : TRect;
  4. begin
  5. bmp1 := TBitmap.create;
  6. bmp1.setsize (200,100);
  7. R := Rect(0,0,bmp1.Width,bmp1.height);
  8. bmp1.Canvas.Brush.Color := clWhite;
  9. bmp1.Canvas.Pen.Color := clRed;
  10. bmp1.canvas.FillRect(R);
  11. bmp1.canvas.Line(R);
  12.  
  13. bmp2 := TBitmap.create;
  14. bmp2.SetSize(200,100);
  15. bmp2.Canvas.CopyRect(R,bmp1.Canvas,R);
  16.  
  17. canvas.copyRect (R,bmp2.canvas,R);
  18. bmp1.free;
  19. bmp2.free;
  20. end;

Winni

Josh

  • Hero Member
  • *****
  • Posts: 930
Re: duplicate tbitmap how?
« Reply #2 on: January 11, 2022, 12:32:41 am »
Hi Winni,

Thanks for that,it un froze my brain...  Back on track now.
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

furious programming

  • Hero Member
  • *****
  • Posts: 568
  • I click a little.
    • TreeStructInfo — format for text and binary configuration files
Re: duplicate tbitmap how?
« Reply #3 on: January 28, 2022, 01:14:19 am »
Also you can use TBitmap.Assign — the result will be the same (exact copy of the source bitmap object).
Lazarus 2.2.0 with FPC 3.2.2 (2022-01-02), Windows 10 — all 64-bit

 

TinyPortal © 2005-2018