Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Graphics and Multimedia
»
Graphics
»
BGRABitmap and LazPaint
»
[SOLVED] Paint image within rounding
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
WIKI Timeout issues
Please read here if you have trouble connecting to the wiki
Recent
InstallAware 2025 Sources...
by
msintle
[July 07, 2025, 11:49:05 pm]
Forte Report CE Questions
by
PascalProg
[July 07, 2025, 11:38:16 pm]
Feature request: hard typ...
by
Martin_fr
[July 07, 2025, 11:35:05 pm]
activex.pp definition pro...
by
440bx
[July 07, 2025, 11:30:43 pm]
[SOLVED] Lazarus IDE 4 UI...
by
Psacla_63
[July 07, 2025, 11:03:06 pm]
Lazarus IDE crashes ( Due...
by
JuhaManninen
[July 07, 2025, 10:44:37 pm]
Conant Fractal (Close to ...
by
Boleeman
[July 07, 2025, 10:38:58 pm]
problem with certain char...
by
tetrastes
[July 07, 2025, 09:22:02 pm]
controls.lpr(731,15) Erro...
by
tetrastes
[July 07, 2025, 08:55:04 pm]
Trouble compiling fpc for...
by
ermok
[July 07, 2025, 08:17:48 pm]
MDI ChildForm
by
Remy Lebeau
[July 07, 2025, 07:59:10 pm]
Fast Canvas Library V1.05...
by
Lulu
[July 07, 2025, 07:58:57 pm]
Library for drawing a pat...
by
gidesa
[July 07, 2025, 07:43:59 pm]
Compiler don't know the S...
by
marcov
[July 07, 2025, 07:16:15 pm]
Canvas.PolyBezier
by
BubikolRamios
[July 07, 2025, 03:18:02 pm]
Sutcliffe Fractal: Anothe...
by
Joanna
[July 07, 2025, 02:16:29 pm]
Billowing Flower: A Tenta...
by
Joanna
[July 07, 2025, 02:13:22 pm]
Spiral Mandala Patterns o...
by
Boleeman
[July 07, 2025, 01:56:56 pm]
definition problem in act...
by
marcov
[July 07, 2025, 01:52:12 pm]
Snaking Triangle Animatio...
by
Boleeman
[July 07, 2025, 01:49:02 pm]
FPC 3.2.2 - non Alpha Nam...
by
MarkMLl
[July 07, 2025, 01:29:04 pm]
[SOLVED] How to query the...
by
rvk
[July 07, 2025, 12:36:25 pm]
FPSpreadsheet v2.0 releas...
by
LV
[July 07, 2025, 12:34:38 pm]
DBF edit & append problem
by
CharlyTango
[July 07, 2025, 11:49:31 am]
Loading so,dll libraries...
by
Thaddy
[July 07, 2025, 06:14:59 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] Paint image within rounding (Read 1780 times)
SaraT
Full Member
Posts: 135
A little student
[SOLVED] Paint image within rounding
«
on:
July 25, 2023, 01:32:04 pm »
Hi, all
I am painting an image on BCButton usin AfterRender event. It works ok, but the image is painted
over
the rounding, so the image looks square, not rounded.
Take a look at the attached image.
Any help will be appreciated.
«
Last Edit: July 26, 2023, 11:08:17 pm by SaraT
»
Logged
KodeZwerg
Hero Member
Posts: 2269
Fifty shades of code.
Re: Paint image within rounding
«
Reply #1 on:
July 25, 2023, 02:41:34 pm »
If your Target is Windows, you can try my attached project that not use your component, its simply a panel with a image attached and got round corners, you can add a click event and than it act like your suggested control.
Logged
«
Last Edit:
Tomorrow
at 31:76:97 xm by
KodeZwerg
»
SaraT
Full Member
Posts: 135
A little student
Re: Paint image within rounding
«
Reply #2 on:
July 25, 2023, 07:00:47 pm »
Quote from: KodeZwerg on July 25, 2023, 02:41:34 pm
If your Target is Windows, you can try my attached project that not use your component...
Thanks a lot, but it does not work with TBCButton control (as you said).
And I dont use the Panel control because I need the TBCButton proeprties.
Maybe someone else can help me.
Regards.
Logged
Josh
Hero Member
Posts: 1375
Re: Paint image within rounding
«
Reply #3 on:
July 25, 2023, 08:54:38 pm »
Hi
just had a play.
Might not be the best solution. Not sure how cross-platform it is either
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
BCButton1AfterRenderBCButton
(
Sender
:
TObject
;
const
ABGRA
:
TBGRABitmap
;
AState
:
TBCButtonState
;
ARect
:
TRect
)
;
Var
MyPic
:
TBGRABitmap
;
rgn
:
HRGN
;
begin
rgn
:
=
CreateRoundRectRgn
(
0
,
0
,
tbcbutton
(
sender
)
.
Width
,
tbcbutton
(
sender
)
.
Height
,
tbcbutton
(
sender
)
.
Rounding
.
RoundX
,
tbcbutton
(
sender
)
.
Rounding
.
RoundY
)
;
MyPic
:
=
TBGRABitmap
.
Create
(
'apic2.png'
)
;
// i placed here for ease of use, this should be a fixed variable, that is not loaded everytime
SelectClipRgn
(
abgra
.
Canvas
.
Handle
,
rgn
)
;
MyPic
.
Bitmap
.
Transparent
:
=
true
;
abgra
.
Canvas
.
StretchDraw
(
arect
,
MyPic
.
Bitmap
)
;
MyPic
.
free
;
end
;
you will need to add to your uses
LclIntF,LclType
Logged
The best way to get accurate information on the forum is to post something wrong and wait for corrections.
Josh
Hero Member
Posts: 1375
Re: Paint image within rounding
«
Reply #4 on:
July 26, 2023, 01:15:09 am »
further playing or hack
using the glyph of the tbcbutton to hold the image, you must set the glyphscale to 0; so that the glyph isnot drawn
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
BCButton1AfterRenderBCButton
(
Sender
:
TObject
;
const
ABGRA
:
TBGRABitmap
;
AState
:
TBCButtonState
;
ARect
:
TRect
)
;
Var
MyPic
:
TBGRABitmap
;
rgn
:
HRGN
;
tw
,
th
,
x
,
y
:
integer
;
Begin
If
Sender is TBCButton
then
// sanity check
Begin
// check if glyph is empty
If
TBitmap
(
TBCButton
(
Sender
)
.
Glyph
)
.
Empty
=
False
then
Begin
// width and height +1 to correct issue
rgn
:
=
CreateRoundRectRgn
(
0
,
0
,
TBCButton
(
Sender
)
.
Width
+
1
,
TBCButton
(
Sender
)
.
Height
+
1
,
TBCButton
(
Sender
)
.
Rounding
.
RoundX
,
TBCButton
(
Sender
)
.
Rounding
.
RoundY
)
;
MyPic
:
=
TBGRABitmap
.
Create
(
TBCButton
(
Sender
)
.
Glyph
)
;
// you must set the button glyphscale to 0
SelectClipRgn
(
ABGRA
.
Canvas
.
Handle
,
rgn
)
;
MyPic
.
Bitmap
.
Transparent
:
=
True
;
MyPic
.
AntialiasingDrawMode
:
=
dmDrawWithTransparency
;
ABGRA
.
Canvas
.
StretchDraw
(
ARect
,
MyPic
.
Bitmap
)
;
// if caption exists display it... work needed
If
TBCButton
(
Sender
)
.
Caption
<>
''
then
Begin
ABGRA
.
Canvas
.
Brush
.
Style
:
=
bsClear
;
ABGRA
.
Canvas
.
Font
.
Name
:
=
AState
.
FontEx
.
Name
;
ABGRA
.
Canvas
.
Font
.
Style
:
=
AState
.
FontEx
.
Style
;
ABGRA
.
Canvas
.
Font
.
Height
:
=
AState
.
FontEx
.
Height
;
ABGRA
.
Canvas
.
Font
.
Color
:
=
AState
.
FontEx
.
Color
;
ABGRA
.
Canvas
.
GetTextSize
(
TBCButton
(
Sender
)
.
Caption
,
tw
,
th
)
;
x
:
=
(
ABGRA
.
Width
-
tw
)
div
2
;
y
:
=
(
ABGRA
.
height
-
th
)
div
2
;
ABGRA
.
Canvas
.
TextOut
(
x
,
y
,
TBCButton
(
Sender
)
.
Caption
)
;
End
;
MyPic
.
Free
;
End
;
End
;
End
;
«
Last Edit: July 26, 2023, 01:31:50 am by Josh
»
Logged
The best way to get accurate information on the forum is to post something wrong and wait for corrections.
circular
Hero Member
Posts: 4443
Re: [SOLVED] Paint image within rounding
«
Reply #5 on:
July 27, 2023, 04:38:58 pm »
Actually with BGRABitmap you can call FillRoundRectAntialias and give an image as parameter for texture. If the image needs to be resized, you can first create a resampled version of the image and use this as the texture parameter of FillRoundRectAntialias.
Logged
Conscience is the debugger of the mind
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Graphics and Multimedia
»
Graphics
»
BGRABitmap and LazPaint
»
[SOLVED] Paint image within rounding
TinyPortal
© 2005-2018