* * *

Author Topic: TBgraBitmap.TakeScreenShot not working on Lazarus 1.x 64 bits - Ubuntu 16.04  (Read 498 times)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 640
hello,
on Lazarus 1.x 64 bits - Ubuntu 16.04   gtk2 interface with this code :
Code: Pascal  [Select]
  1. procedure TForm1.Button3Click(Sender: TObject);
  2. var MyCapture : TBgraBitmap;
  3. var MyArea : TRect;
  4. begin
  5.   MyArea := Bounds(400,400,500,500);
  6.   MyCapture := TBgraBitmap.Create();
  7.   MyCapture.TakeScreenShot(MyArea);
  8.   MyCapture.SaveToFile('/home/jurassic/MyCapture.png');
  9. end;
i have this error message when i call TakeScreenShot :
Code: Pascal  [Select]
  1. Cannot get raw image from device

error in this code :
Code: Pascal  [Select]
  1. procedure TBGRALCLBitmap.LoadFromDevice(DC: System.THandle; ARect: TRect);
  2. var
  3.   rawImage: TRawImage;
  4. begin
  5.   if (ARect.Right <= ARect.Left) or (ARect.Bottom <= ARect.Top) then
  6.   begin
  7.     SetSize(0,0);
  8.     exit;
  9.   end;
  10.   try
  11.     if not RawImage_FromDevice(rawImage, DC, ARect) then
  12.       raise Exception.Create('Cannot get raw image from device');
  13.     SetSize(rawImage.Description.Width, rawImage.Description.Height);
  14.     LoadFromRawImage(rawImage,255);
  15.   finally
  16.     rawImage.FreeData;
  17.   end;
  18. end;

so what is wrong : 
it seems that it is the DC pointer type . If in all the files of the tbgrabitmap package, i replace DC : System.THandle by  : DC : PtrUInt TakeScreenshot works.
Is it a good idea ?

Ami calmant, J.P

« Last Edit: July 15, 2017, 09:29:55 am by Jurassic Pork »

circular

  • Hero Member
  • *****
  • Posts: 2600
    • Personal webpage
Hi,

PtrUInt seems ok, however it may be better to use a type defined for such handes. Apparently, System.THandle is not the right one. Is HDC type available? What about the definition of RawImage_FromDevice, what type is used in its parameters?
Conscience is the debugger of the mind

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 640
HDC type seems to be defined in lcltype unit (lcltype.pp) :
Code: Pascal  [Select]
  1. type HDC = type THandle;
  2. type THandle = type PtrUInt;
  3.  

and RawImage_fromdevice seems to use HDC :
Code: Pascal  [Select]
  1. function RawImage_FromDevice(out ARawImage: TRawImage; ADC: HDC; const ARect: TRect): Boolean; override;

may be you can change  some bgrabitmap files. Something like that :
Quote
for lctype :
bgrabitmap-master/bgrabitmap/bgrabitmaptypes.pas
bgrabitmap/bgrabitmaptypes.pas (34,32) Classes, Types, BGRAGraphics,lcltype,

bgrabitmap-master/bgrabitmap/bgradefaultbitmap.pas
bgrabitmap/bgradefaultbitmap.pas (36,63) BGRACanvas, BGRACanvas2D, BGRAArrow, BGRAPen, BGRATransform,lcltype;
bgrabitmap-master/bgrabitmap/bgralclbitmap.pas
bgrabitmap/bgralclbitmap.pas (8,42) Classes, SysUtils, Graphics, GraphType,lcltype, BGRABitmapTypes, BGRADefaultBitm...

for HDC :
bgrabitmap-master/bgrabitmap/bgradefaultbitmap.pas
bgradefaultbitmap.pas (903,35) procedure LoadFromDevice({%H-}DC: HDC); override;
bgradefaultbitmap.pas (904,35) procedure LoadFromDevice({%H-}DC: HDC; {%H-}ARect: TRect); override;
bgradefaultbitmap.pas (6077,41) procedure TBGRAPtrBitmap.LoadFromDevice(DC: HDC);
bgradefaultbitmap.pas (6082,41) procedure TBGRAPtrBitmap.LoadFromDevice(DC: HDC; ARect: TRect);

bgrabitmap-master/bgrabitmap/bgralclbitmap.pas
bgralclbitmap.pas (31,35) procedure LoadFromDevice({%H-}DC: HDC); override;
bgralclbitmap.pas (32,35) procedure LoadFromDevice({%H-}DC: HDC; {%H-}ARect: TRect); override;
bgralclbitmap.pas (878,41) procedure TBGRALCLBitmap.LoadFromDevice(DC: HDC);
bgralclbitmap.pas (900,41) procedure TBGRALCLBitmap.LoadFromDevice(DC: HDC; ARect: TRect);

bgrabitmap-master/bgrabitmap/bgracustombitmap.inc
bgracustombitmap.inc (390,31) procedure LoadFromDevice(DC: HDC); virtual; abstract; overload;
bgracustombitmap.inc (392,31) procedure LoadFromDevice(DC: HDC; ARect: TRect); virtual; abstract; overload;

« Last Edit: July 16, 2017, 12:53:45 am by Jurassic Pork »

circular

  • Hero Member
  • *****
  • Posts: 2600
    • Personal webpage
Ok. I applied changes following this idea in "dev-bgrabitmap" branch. Does it fix the problem?
Conscience is the debugger of the mind

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 640
hello,
thanks circular, i have downloaded the dev-bgrabitmap version of bgrapbitmap. It seems to be OK for the TakeScreenshot function on Ubuntu 16.04  64 bits Lazarus 1.8RC3 64 bits.

Ami calmant, J.P

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus