Recent

Author Topic: [Answered, no solution] GetFormImage on MacOS generates black bitmap  (Read 1824 times)

wittbo

  • Full Member
  • ***
  • Posts: 150
Given this simple procedure:

procedure TmyForm.Button1Click(Sender: TObject);
var bm: TBitmap;
begin
   bm := myForm.GetFormImage;
   bm.Canvas.Changed;
   bm.SaveToFile('/users/myuser/downloads/test.bmp');
   bm.Free
end;

The file gets generated with the correct dimensions width and height, but the contents of the bitmap in the file is entirely black.
Any idea?
Does GetFormImage only work on Windows?
« Last Edit: June 05, 2019, 10:41:19 am by wittbo »
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: GetFormImage on MacOS generates black bitmap
« Reply #1 on: June 03, 2019, 04:59:55 pm »
Does GetFormImage only work on Windows?

No, it works also on Linux. See attached image, made using:
Code: Pascal  [Select][+][-]
  1. procedure TMainForm.btDoTestClick(Sender: TObject);
  2. var
  3.   Bitmap: TBitmap;
  4. begin
  5.   Bitmap := GetFormImage;
  6.   if Assigned(Bitmap) then
  7.   try
  8.     {Bitmap.Canvas.Changed; - not needed: there's no OnChange handler}
  9.     Bitmap.SaveToFile('test.bmp');
  10.     Image.Picture.LoadFromFile('test.bmp');
  11.   finally
  12.     Bitmap.Free;
  13.   end;
  14. end;

Unrelated, but note that it is very bad practice to reference the auto-created form instance inside the methods. If you realy need to reference the current object use Self, as in:
Self.GetFormImage
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

bylaardt

  • Sr. Member
  • ****
  • Posts: 309

wittbo

  • Full Member
  • ***
  • Posts: 150
Re: GetFormImage on MacOS generates black bitmap
« Reply #3 on: June 04, 2019, 11:13:43 am »
Sorry, but none of the solutions (GetFormimage, ...copyrect, ...) does work on MacOS. The Bitmap remains black.

I believe, it is a special MacOS problem(or cocoa): i will copy a link to this thread into the macos forum.
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

bylaardt

  • Sr. Member
  • ****
  • Posts: 309
Re: GetFormImage on MacOS generates black bitmap
« Reply #4 on: June 04, 2019, 05:19:47 pm »
even paintto?

wittbo

  • Full Member
  • ***
  • Posts: 150
Re: GetFormImage on MacOS generates black bitmap
« Reply #5 on: June 05, 2019, 10:39:47 am »
Skalogryz wrote in the correspondent macos thread:  that's easy. The function has not been implemented for cocoa yet
https://forum.lazarus.freepascal.org/index.php/topic,45606.0.html

Therefore actually no solution for Mac users.
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

bylaardt

  • Sr. Member
  • ****
  • Posts: 309
Re: [Answered, no solution] GetFormImage on MacOS generates black bitmap
« Reply #6 on: June 05, 2019, 03:46:14 pm »
have you try?
Code: Pascal  [Select][+][-]
  1. MyCapture:=TBitMap.Create(application);
  2.   MyCapture.SetSize(ClientWidth,ClientHeight);
  3.   MyCapture.canvas.FillRect(0,0,ClientWidth,ClientHeight);
  4.   self.PaintTo(MyCapture.canvas,0,0);
  5.   MyCapture.SaveToFile('/home/bylaardt/MyFormImage.bmp');
  6.   MyCapture.free;

wittbo

  • Full Member
  • ***
  • Posts: 150
Re: [Answered, no solution] GetFormImage on MacOS generates black bitmap
« Reply #7 on: June 06, 2019, 11:56:39 am »
Sorry, just tested.
But now the Image isn't black, now it's completely white.
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

 

TinyPortal © 2005-2018