Recent

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

wittbo

  • Jr. Member
  • **
  • Posts: 65
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-
Lazarus 2.0.4  with FPC 3.0.4a
MBAir with MacOS 10.14.5
iMac with MacOS 10.13.6

lucamar

  • Hero Member
  • *****
  • Posts: 2014
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 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

bylaardt

  • Sr. Member
  • ****
  • Posts: 303

wittbo

  • Jr. Member
  • **
  • Posts: 65
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-
Lazarus 2.0.4  with FPC 3.0.4a
MBAir with MacOS 10.14.5
iMac with MacOS 10.13.6

bylaardt

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

wittbo

  • Jr. Member
  • **
  • Posts: 65
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-
Lazarus 2.0.4  with FPC 3.0.4a
MBAir with MacOS 10.14.5
iMac with MacOS 10.13.6

bylaardt

  • Sr. Member
  • ****
  • Posts: 303
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

  • Jr. Member
  • **
  • Posts: 65
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-
Lazarus 2.0.4  with FPC 3.0.4a
MBAir with MacOS 10.14.5
iMac with MacOS 10.13.6