Jump to content
shineworld

Modify bitmap of FMX Image object

Recommended Posts

Hi all.

There is a way to modify Bitmap contents (actually create content) of a DelphiFMX Image.Bitmap to add a text ?

I've tried:

            bitmap = self.DIOImage.Bitmap
            bitmap.Width = int(self.DIOImage.Width)
            bitmap.Height = int(self.DIOImage.Height)
            bitmap.Clear(0xFF000000)
            canvas = bitmap.Canvas
            r = RectF(8 + 15, 10, bitmap.Width - 8, bitmap.Height - 10)
            ??? canvas.FillText(r, 'Hello World', False, 100, 0, 0, 0) ???

But the image remains EMPTY and doesn't show anything...

Edited by shineworld

Share this post


Link to post

OK Bitmap can be modified not, but I was not able to find how to use TCanvas.FillText with Python DelphiFMX.

Any try to pass arguments give me:

Traceback (most recent call last):
  File "D:\x\develop\qem\cnc_api_client_core_1\python\api_client_fmx_demo\api_client_fmx_demo_desktop_view.py", line 690, in __on_timer_update
    canvas.FillText(r, 'hello world', False, 100.0, None, 'Center', 'Center')
TypeError: "FillText" called with invalid arguments.

 

        # update tab digital inputs/outputs values
        if self.TabControl.ActiveTab == self.TabDIO:
            bitmap = self.DIOImage.Bitmap
            bitmap.Width = int(self.DIOImage.Width)
            bitmap.Height = int(self.DIOImage.Height)
            bitmap.Clear(0xFF000000)
            canvas = bitmap.Canvas
            r = RectF(8 + 15, 10, bitmap.Width - 8, bitmap.Height - 10)
            # from delphi FMX documentation
            # procedure FillText(
            #       const ARect: TRectF;
            #       const AText: string;
            #       const WordWrap: Boolean;
            #       const AOpacity: Single;
            #       const Flags: TFillTextFlags;
            #       const ATextAlign: TTextAlign;
            #       const AVTextAlign: TTextAlign = TTextAlign.Center
            #   ); virtual;
            canvas.FillText(r, 'hello world', False, 100.0, None, 'Center', 'Center')


 

Share this post


Link to post
canvas.FillText(r, 'hello world', False, 1, [], TTextAlign.Center, TTextAlign.Center);
Edited by Christophe E.

Share this post


Link to post

Seems TTextAlign is not available in DelphiFMX library :

 

Microsoft Windows [Versione 10.0.19045.2965]
(c) Microsoft Corporation. Tutti i diritti sono riservati.

P:\>pip list
Package                Version
---------------------- ------------
delphifmx              1.0.6

 
 
NameError: name 'TTextAlign' is not defined
Traceback (most recent call last):
  File "D:\x\develop\qem\cnc_api_client_core_1\python\api_client_fmx_demo\api_client_fmx_demo_desktop_view.py", line 692, in __on_timer_update
    canvas.FillText(r, 'hello world', False, 1, [], TTextAlign.Center, TTextAlign.Center)
                                                    ^^^^^^^^^^
NameError: name 'TTextAlign' is not defined
 
*** Remote Interpreter Reinitialized ***
>>> import delphifmx as fmx
>>> dir(fmx)
['Abort',
 'Action',
 'ActionList',
 'AdapterListView',
 'AniIndicator',
 'AppearanceListView',
 'Application',
 'Arc',
 'ArcDial',
 'BaseBindScopeComponent',
 'BaseLinkingBindSource',
 'BaseObjectBindSource',
 'BaseValueRange',
 'BasicAction',
 'BasicBindComponent',
 'BindComponentDelegate',
 'BindingsList',
 'BitmapTrackBar',
 'Bounds',
 'BufferedFileStream',
 'BufferedLayout',
 'Button',
 'BytesStream',
 'Calendar',
 'CalloutPanel',
 'CalloutRectangle',
 'CameraComponent',
 'CaretRectangle',
 'CheckBox',
 'CheckColumn',
 'Circle',
 'Collection',
 'ColorBox',
 'ColorButton',
 'ColorComboBox',
 'ColorListBox',
 'ColorPanel',
 'ColorPicker',
 'ColorQuad',
 'Column',
 'ComboBox',
 'ComboColorBox',
 'ComboEdit',
 'ComboEditBase',
 'CommonCustomForm',
 'Component',
 'ContainedAction',
 'ContainedActionList',
 'ContainedBindComponent',
 'Control',
 'ControlSize',
 'CornerButton',
 'CreateComponent',
 'CurrencyColumn',
 'CustomAction',
 'CustomActionList',
 'CustomBindingsList',
 'CustomBufferedLayout',
 'CustomButton',
 'CustomCalendar',
 'CustomColorComboBox',
 'CustomComboBox',
 'CustomComboEdit',
 'CustomControlAction',
 'CustomCornerButton',
 'CustomDateEdit',
 'CustomDateTimeEdit',
 'CustomEdit',
 'CustomEditBox',
 'CustomForm',
 'CustomGrid',
 'CustomLinkControlToField',
 'CustomLinkListControlToField',
 'CustomLinkPropertyToField',
 'CustomListBox',
 'CustomListView',
 'CustomMediaCodec',
 'CustomMediaPlayerAction',
 'CustomMemo',
 'CustomMemoryStream',
 'CustomMultiView',
 'CustomNumberColumn',
 'CustomPath',
 'CustomPopupForm',
 'CustomPopupMenu',
 'CustomPresentedFramedScrollBox',
 'CustomPresentedFramedVertScrollBox',
 'CustomPresentedHorzScrollBox',
 'CustomPresentedScrollBox',
 'CustomPresentedVertScrollBox',
 'CustomPrototypeBindSource',
 'CustomScrollBox',
 'CustomSwitch',
 'CustomTimeEdit',
 'CustomTrack',
 'CustomValueRange',
 'CustomValueRangeAction',
 'CustomViewAction',
 'DateColumn',
 'DateEdit',
 'DateTimeColumn',
 'DateTimeColumnBase',
 'DelphiDefaultContainer',
 'DelphiDefaultIterator',
 'DelphiMethod',
 'DialogService',
 'Edit',
 'Ellipse',
 'Expander',
 'ExpanderButton',
 'FMXBindNavigateAction',
 'FMXBindNavigateApplyUpdates',
 'FMXBindNavigateCancel',
 'FMXBindNavigateCancelUpdates',
 'FMXBindNavigateDelete',
 'FMXBindNavigateEdit',
 'FMXBindNavigateFirst',
 'FMXBindNavigateInsert',
 'FMXBindNavigateLast',
 'FMXBindNavigateNext',
 'FMXBindNavigatePost',
 'FMXBindNavigatePrior',
 'FMXBindNavigateRefresh',
 'FileExit',
 'FileHideApp',
 'FileHideAppOthers',
 'FileStream',
 'FloatColumn',
 'FlowLayout',
 'FmxObject',
 'Form',
 'Frame',
 'FramedScrollBox',
 'FramedVertScrollBox',
 'GetProcessDpiAwareness',
 'GlyphColumn',
 'GradientEdit',
 'Grid',
 'GridLayout',
 'GridPanelLayout',
 'GroupBox',
 'HandleStream',
 'HintAction',
 'HorzScrollBox',
 'IDABORT',
 'IDCANCEL',
 'IDCLOSE',
 'IDCONTINUE',
 'IDHELP',
 'IDIGNORE',
 'IDNO',
 'IDOK',
 'IDRETRY',
 'IDTRYAGAIN',
 'IDYES',
 'Image',
 'ImageColumn',
 'ImageControl',
 'IntegerColumn',
 'IsDpiAware',
 'Label',
 'Layout',
 'Line',
 'LinkControlDelegate',
 'LinkControlToField',
 'LinkControlToFieldDelegate',
 'LinkListControlToField',
 'LinkPropertyToField',
 'LinkPropertyToFieldDelegate',
 'ListBox',
 'ListBoxItem',
 'ListView',
 'ListViewBase',
 'MB_ABORTRETRYIGNORE',
 'MB_APPLMODAL',
 'MB_DEFBUTTON1',
 'MB_DEFBUTTON2',
 'MB_DEFBUTTON3',
 'MB_DEFBUTTON4',
 'MB_HELP',
 'MB_ICONASTERISK',
 'MB_ICONERROR',
 'MB_ICONEXCLAMATION',
 'MB_ICONHAND',
 'MB_ICONINFORMATION',
 'MB_ICONQUESTION',
 'MB_ICONSTOP',
 'MB_ICONWARNING',
 'MB_NOFOCUS',
 'MB_OK',
 'MB_OKCANCEL',
 'MB_RETRYCANCEL',
 'MB_SYSTEMMODAL',
 'MB_TASKMODAL',
 'MB_YESNO',
 'MB_YESNOCANCEL',
 'MainMenu',
 'Media',
 'MediaPlayer',
 'MediaPlayerControl',
 'MediaPlayerCurrentTime',
 'MediaPlayerPlayPause',
 'MediaPlayerStart',
 'MediaPlayerStop',
 'MediaPlayerValue',
 'MediaPlayerVolume',
 'Memo',
 'MemoryStream',
 'MenuBar',
 'MenuItem',
 'MultiView',
 'NumberBox',
 'Object',
 'ObjectViewAction',
 'OpenDialog',
 'PaintBox',
 'Panel',
 'PascalInterface',
 'PascalRecord',
 'Path',
 'PathLabel',
 'Persistent',
 'Pie',
 'Point',
 'PointF',
 'Popup',
 'PopupColumn',
 'PopupMenu',
 'Position',
 'PresentedFramedScrollBox',
 'PresentedFramedVertScrollBox',
 'PresentedHorzScrollBox',
 'PresentedListView',
 'PresentedScrollBox',
 'PresentedTextControl',
 'PresentedVertScrollBox',
 'ProgressBar',
 'ProgressColumn',
 'PrototypeBindSource',
 'RadioButton',
 'Rect',
 'RectF',
 'Rectangle',
 'ResourceStream',
 'RoundRect',
 'SaveDialog',
 'ScaledLayout',
 'Screen',
 'ScrollBar',
 'ScrollBox',
 'SearchBox',
 'Selection',
 'SelectionPoint',
 'SetHighDpiAware',
 'SetProcessDpiAwareness',
 'Shape',
 'Size',
 'SizeF',
 'SizeGrip',
 'SmallScrollBar',
 'SpeedButton',
 'SpinBox',
 'Splitter',
 'StatusBar',
 'Stream',
 'StringColumn',
 'StringGrid',
 'StringStream',
 'Strings',
 'StyleBook',
 'StyleManager',
 'StyleStreaming',
 'StyledControl',
 'Switch',
 'SysCommonAction',
 'TabControl',
 'TabItem',
 'Text',
 'TextControl',
 'Thumb',
 'TimeColumn',
 'TimeEdit',
 'Timer',
 'ToolBar',
 'Touch',
 'Track',
 'TrackBar',
 'ValueRange',
 'ValueRangeAction',
 'VarParameter',
 'VertScrollBox',
 'ViewAction',
 'VirtualKeyboard',
 'WindowClose',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 'crAppStart',
 'crArrow',
 'crCross',
 'crDefault',
 'crDrag',
 'crHSplit',
 'crHandPoint',
 'crHelp',
 'crHourGlass',
 'crIBeam',
 'crMultiDrag',
 'crNo',
 'crNoDrop',
 'crNone',
 'crSQLWait',
 'crSize',
 'crSizeAll',
 'crSizeNESW',
 'crSizeNS',
 'crSizeNWSE',
 'crSizeWE',
 'crUpArrow',
 'crVSplit',
 'fmCreate',
 'fmOpenRead',
 'fmOpenReadWrite',
 'fmOpenWrite',
 'fmShareCompat',
 'fmShareDenyNone',
 'fmShareDenyRead',
 'fmShareDenyWrite',
 'fmShareExclusive',
 'ssAlt',
 'ssCtrl',
 'ssDouble',
 'ssLeft',
 'ssMiddle',
 'ssRight',
 'ssShift']
>>> 

 

 

Share this post


Link to post

Mmmmm.... seems that Canvas.FillText can't be used...

 

image.thumb.png.4042bff8b065f59d95263f41b56ad0dc.png

 

I'm not a guru on Python and DelphiFMX so I can mistake in anything but debugging:
 

>>> import DelphiFMX as fmx
>>> img = fmx.Image(None)
>>> bmp = img.Bitmap
>>> bmp.Handle
>>> bmp.Width = 200
>>> bmp.Height = 200
>>> c = bmp.Canvas
>>> r = fmx.RectF(0,0,10,10)
>>> c.FillText(r, 'hello', True, 1, [], ['Center'], ['Center'])

the FindMethod "find" FillRect and first ARect parameter in FMX is a Record when
Python call to c.FillText manages R as a class so the arguments check stops at the first argument with an error.

 

Waiting for GURU info 🙂

Edited by shineworld

Share this post


Link to post

Seems that Canvas object is not usable in DelphiFMX.

c.BeginScene() does not works also passing (None, 0) or any other combination:

import delphifmx as fmx
img = fmx.Image(None)
bmp = img.Bitmap
print(f'Initial Image Width         : {img.Width}')
print(f'Initial Image Height        : {img.Height}')
print(f'Initial Image.Bitmap Width  : {img.Bitmap.Width}')
print(f'Initial Image.Bitmap Height : {img.Bitmap.Height}')
bmp.Width = 200
bmp.Height = 200
img.Width = bmp.Width
img.Height = bmp.Height
print(f'Actual Image Width          : {img.Width}')
print(f'Actual Image Height         : {img.Height}')
print(f'Actual Image.Bitmap Width   : {img.Bitmap.Width}')
print(f'Actual Image.Bitmap Height  : {img.Bitmap.Height}')
c = bmp.Canvas
print(f'Canvas Width                : {c.Width}')
print(f'Canvas Height               : {c.Height}')
r = fmx.RectF(0.0, 0.0, 100.0, 100.0)
c.BeginScene(None, 0)
try:
    pass
    #c.FillText(r, 'hello', True, 1, [], 'Center', 'Center')
finally:
    c.EndScene()
*** Remote Interpreter Reinitialized ***
Initial Image Width         : 50.0
Initial Image Height        : 50.0
Initial Image.Bitmap Width  : 0
Initial Image.Bitmap Height : 0
Actual Image Width          : 200.0
Actual Image Height         : 200.0
Actual Image.Bitmap Width   : 200
Actual Image.Bitmap Height  : 200
Canvas Width                : 200
Canvas Height               : 200
Traceback (most recent call last):
  File "D:\x\develop\qem\cnc_api_client_core_1\python\api_client_fmx_demo\test-001.py", line 30, in <module>
    c.BeginScene(None, 0)
TypeError: "BeginScene" called with invalid arguments.
Error: Expected and actual arguments are incompatible
>>> 


 

Share this post


Link to post
On 11/13/2024 at 4:49 PM, shineworld said:

Seems that Canvas object is not usable in DelphiFMX.

Unlike DelphiVcl, DelphiFMX does not wrap Canvas.

 

Both DelphiVcl and DelphiFmx are maintained by Embarcadero.  There is a reported issue regarding BeginScene, but you may want to submit a broader one about Canvas support.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×