Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: phampl on March 28, 2019, 09:47:03 pm

Title: BGRABitmap textout does not work in simple console app
Post by: phampl on March 28, 2019, 09:47:03 pm
When I create FP console application on Win7/64bit, make BGRABitmap and try to insert text, I get an error

This is the code:

program project1;

Code: Pascal  [Select][+][-]
  1. uses classes, sysutils,
  2.      BGRABitmap, BGRABitmapTypes;
  3. var
  4.     bmp: TBGRABitmap;
  5.     x,y: integer;
  6.     p: TBGRAPixel;
  7. begin
  8.   bmp := TBGRABitmap.Create(800,600, BGRAblack);
  9.   p:=tbgrapixel.New(200,0,100);
  10.   bmp.fontname:='Arial';
  11.   bmp.fontheight:=20;
  12.   bmp.TextOut(200,200, 'help',p,taleftjustify);    // here I get the error
  13.   bmp.SaveToFile('pokusbgra.png');
  14.   bmp.free;
  15. end.


and this is the console error message:

Quote
An unhandled exception occurred at $0000000100168537:
EAccessViolation: Access violation
  $0000000100168537 line 405 of ../../../../../lazarus/fpc/3.0.4/units/x86_64-win64/bgrabitmap/bgratext.pas
  $000000010016872E line 534 of ../../../../../lazarus/fpc/3.0.4/units/x86_64-win64/bgrabitmap/bgratext.pas
  $000000010016A4C2 line 1074 of ../../../../../lazarus/fpc/3.0.4/units/x86_64-win64/bgrabitmap/bgratext.pas
  $000000010016AC59 line 1168 of ../../../../../lazarus/fpc/3.0.4/units/x86_64-win64/bgrabitmap/bgratext.pas
  $000000010007E5F2 line 4069 of ../../../../../lazarus/fpc/3.0.4/units/x86_64-win64/bgrabitmap/bgradefaultbitmap.pas
  $0000000100037E19 line 1913 of ../../../../../lazarus/fpc/3.0.4/units/x86_64-win64/bgrabitmap/bgracustombitmap.inc
  $000000010000185A line 15 of project1.lpr
  $0000000100001896
  $0000000100013F93
  $0000000100014A91
  $000000007755571D
  $00000000777B385D
Title: Re: BGRABitmap textout does not work in simple console app
Post by: lainz on March 28, 2019, 10:55:08 pm
I think you need to install package BGRABitmap4nogui to use it in console applications.
Title: Re: BGRABitmap textout does not work in simple console app
Post by: phampl on March 29, 2019, 08:35:06 am
When I insert the bgrabitmappack4nogui.lpk into the project, I get compilation error in BGRABitmapTypes.pas line 1165:

Code: Pascal  [Select][+][-]
  1. const
  2.   ResourceTypes: array[1..7] of TResourceType =
  3.    ((ext: 'CUR'; code: RT_GROUP_CURSOR),   // this RT... constants are unknown
  4.     (ext: 'BMP'; code: RT_BITMAP),
  5.     (ext: 'ICO'; code: RT_GROUP_ICON),
  6.     (ext: 'DAT'; code: RT_RCDATA),
  7.     (ext: 'DATA'; code: RT_RCDATA),
  8.     (ext: 'HTM'; code: RT_HTML),
  9.     (ext: 'HTML'; code: RT_HTML));
  10.  

Those constants are defined in BGRAWinresource which is not included here. If I include it, there is another error at the same place:

Code: Pascal  [Select][+][-]
  1. bgrabitmaptypes.pas(1165,39) Error: Incompatible types: got "ShortInt" expected "PChar"
  2.  
Title: Re: BGRABitmap textout does not work in simple console app
Post by: Ñuño_Martínez on March 29, 2019, 01:35:43 pm
Do not include the lpk file in the project:  you should install the package in to Lazarus instead.  Do it from menu "Packages > Install/uninstall packages..." or "Packages > Open package file (.lpk)..."
Title: Re: BGRABitmap textout does not work in simple console app
Post by: lainz on March 29, 2019, 07:57:07 pm
When I insert the bgrabitmappack4nogui.lpk into the project, I get compilation error in BGRABitmapTypes.pas line 1165:

Code: Pascal  [Select][+][-]
  1. const
  2.   ResourceTypes: array[1..7] of TResourceType =
  3.    ((ext: 'CUR'; code: RT_GROUP_CURSOR),   // this RT... constants are unknown
  4.     (ext: 'BMP'; code: RT_BITMAP),
  5.     (ext: 'ICO'; code: RT_GROUP_ICON),
  6.     (ext: 'DAT'; code: RT_RCDATA),
  7.     (ext: 'DATA'; code: RT_RCDATA),
  8.     (ext: 'HTM'; code: RT_HTML),
  9.     (ext: 'HTML'; code: RT_HTML));
  10.  

Those constants are defined in BGRAWinresource which is not included here. If I include it, there is another error at the same place:

Code: Pascal  [Select][+][-]
  1. bgrabitmaptypes.pas(1165,39) Error: Incompatible types: got "ShortInt" expected "PChar"
  2.  

Please report it in issues page
https://github.com/bgrabitmap/bgrabitmap/issues
Title: Re: BGRABitmap textout does not work in simple console app
Post by: phampl on March 31, 2019, 08:33:15 pm
OK, Ihave reported it as an issue, but now there is a question.

I have console app using BGRABitmap to create some image. How can I put some text into it for now? Is it possible to use some other type of bitmap, create the text in it and then copy the text rectangle into the BGRABitmap? I am not quite familiar with the FPC-Lazarus solutions and after searching in guides I did not find a way which i could understand enough. The BGRA is easy for me to use RGB values directly without any palette. Is there any simple way for it, as I don't know when the issue could be repaired and I need some solution quite soon. I tried the fpimage but could not use RGB directly, only through palette.
Title: Re: BGRABitmap textout does not work in simple console app
Post by: lainz on March 31, 2019, 09:56:04 pm
Include and initialize the LCL and use regular BGRABitmap on the console application.

I don't know how that can work without forms, someone else must know.
Title: Re: BGRABitmap textout does not work in simple console app
Post by: phampl on April 01, 2019, 09:47:33 am
Great, I just added "uses Interfaces" and it started to work immediately. Thank you very much, Lainz!
Title: Re: BGRABitmap textout does not work in simple console app
Post by: circular on October 22, 2019, 06:09:47 pm
Some update about it: the missing constants are indeed missing for fpGUI on Windows, maybe due to a relatively recent change in System unit.

I have applied a workaround (on dev branch) so that BGRABitmap compiles fine in this case.

Regarding text, you need to specify a directory where some fonts are. You need to have Arial in it at least. See test4fpgui example:
https://github.com/bgrabitmap/bgrabitmap/tree/master/test/test4other
Title: Re: BGRABitmap textout does not work in simple console app
Post by: upsidasi on December 11, 2019, 12:46:55 pm
Those constants are still missing if you try to compile 'test4nogui.lpi' on Windows. Both on dev and v10.6.4 branches. Probably due to the fact that they are defined only if "{$IFDEF BGRABITMAP_USE_FPGUI}".
Title: Re: BGRABitmap textout does not work in simple console app
Post by: circular on December 11, 2019, 06:50:59 pm
Oh I see.

I've added the case of noGUI on dev branch.
Title: Re: BGRABitmap textout does not work in simple console app
Post by: upsidasi on December 12, 2019, 10:54:26 am
Thank you for your quick response. But your code does not work:

Code: Pascal  [Select][+][-]
  1. {$IFDEF defined(BGRABITMAP_USE_FPGUI) or defined(BGRABITMAP_DONT_USE_LCL)}{$IFDEF MSWINDOWS}
  2. const
  3.   RT_BITMAP = MAKEINTRESOURCE(2);
  4.   RT_RCDATA = MAKEINTRESOURCE(10);
  5.   RT_GROUP_CURSOR = MAKEINTRESOURCE(12);
  6.   RT_GROUP_ICON = MAKEINTRESOURCE(14);
  7.   RT_HTML = MAKEINTRESOURCE(23);
  8. {$ENDIF}{$ENDIF}
  9.  

It seems to work if I use $IF instead of $IFDEF.
Title: Re: BGRABitmap textout does not work in simple console app
Post by: circular on December 12, 2019, 08:38:04 pm
Oops that's right.

I've put $IF instead.

We're getting there!
Title: Re: BGRABitmap textout does not work in simple console app
Post by: upsidasi on December 13, 2019, 05:43:51 am
It works like a charm now, thank you very much!
Title: Re: BGRABitmap textout does not work in simple console app
Post by: circular on December 22, 2019, 08:28:53 pm
You're welcome.

Thanx for the feedback
TinyPortal © 2005-2018