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
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
had a question and found ...
by
egsuh
[
Today
at 03:57:14 am]
Interesting article about...
by
Joanna from IRC
[
Today
at 03:21:00 am]
[Solved]Printing unicode ...
by
cdbc
[
Today
at 02:47:40 am]
How to set the desktop co...
by
Fibonacci
[
Today
at 02:42:15 am]
MIDI commands
by
finlazarus
[
Today
at 02:26:09 am]
FPSpreadSheet, ReadAsText...
by
andresayang
[
Today
at 02:13:18 am]
Lazarus for Windows on aa...
by
msintle
[
Today
at 01:53:20 am]
Common File Dialogs Have ...
by
msintle
[
Today
at 01:52:27 am]
Game Music Emulator
by
TRon
[
Today
at 01:23:56 am]
Constants in constant exp...
by
440bx
[December 08, 2024, 11:41:59 pm]
ColorDialog can have opti...
by
Bart
[December 08, 2024, 09:14:55 pm]
Array of String lookup gi...
by
TRon
[December 08, 2024, 09:04:03 pm]
kernel 6.8 and checking s...
by
MarkMLl
[December 08, 2024, 08:12:08 pm]
AVRPascal – free code edi...
by
ackarwow
[December 08, 2024, 07:34:07 pm]
Api/component pack for Ra...
by
MarkMLl
[December 08, 2024, 07:11:01 pm]
SAVE StringGrid to PDF
by
dseligo
[December 08, 2024, 06:37:39 pm]
How to save a Graphic fro...
by
Hartmut
[December 08, 2024, 05:57:03 pm]
Array of String lookup gi...
by
Wilko500
[December 08, 2024, 05:47:16 pm]
Developing a Kernel Modul...
by
Joanna from IRC
[December 08, 2024, 04:35:26 pm]
How to get hash of entire...
by
Warfley
[December 08, 2024, 01:30:18 pm]
IFS Fractals: Iterating t...
by
Dzandaa
[December 08, 2024, 11:51:08 am]
Баги CYBERGRAPHICS AmigaO...
by
Smalovsky
[December 08, 2024, 09:39:52 am]
C operators and shift
by
MarkMLl
[December 08, 2024, 09:33:12 am]
fphttpapp and Windows Ser...
by
Thaddy
[December 08, 2024, 08:36:36 am]
MIDI file generator - wor...
by
finlazarus
[December 08, 2024, 02:49:40 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] Paint image within rounding (Read 1549 times)
SaraT
Full Member
Posts: 131
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: 131
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: 1344
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: 1344
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: 4356
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