Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Graphics and Multimedia
»
Graphics
(Moderator:
Ask
) »
[SOLVED] Transparent TBGRABitmap copied/assigned to TImage loses transparency
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
IRC channel
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
Lazarus for Windows on aa...
by
Wallaby
[April 23, 2024, 11:46:56 pm]
Parameter passing odditie...
by
KodeZwerg
[April 23, 2024, 11:04:39 pm]
Can function be used for ...
by
jamie
[April 23, 2024, 10:53:10 pm]
(Solved) TIndexedAVLTree ...
by
lainz
[April 23, 2024, 10:49:03 pm]
Demo Scene Picture sinwav...
by
KodeZwerg
[April 23, 2024, 10:26:21 pm]
fkInternalCalc
by
zraja
[April 23, 2024, 09:31:07 pm]
A fairly simple sound sol...
by
KodeZwerg
[April 23, 2024, 09:23:37 pm]
add new targets to make
by
marcov
[April 23, 2024, 08:38:42 pm]
how to tweek fpmake to co...
by
marcov
[April 23, 2024, 08:29:16 pm]
Quirky windows
by
ASerge
[April 23, 2024, 07:07:16 pm]
[Request] Demo Scene Sub ...
by
Gigatron
[April 23, 2024, 06:29:39 pm]
Unlocking Files
by
KodeZwerg
[April 23, 2024, 06:03:08 pm]
[SOLVED] trunk bug for mi...
by
Key-Real
[April 23, 2024, 05:56:32 pm]
Demo Scene Bitmap Font Sc...
by
Gigatron
[April 23, 2024, 05:56:27 pm]
Compile/Convert Delphi pr...
by
Martin_fr
[April 23, 2024, 05:43:11 pm]
Generics - correct syntax
by
Thaddy
[April 23, 2024, 05:40:59 pm]
InstallAware Using Lazaru...
by
msintle
[April 23, 2024, 05:26:36 pm]
Xcode Command Line Tools ...
by
Joseph
[April 23, 2024, 05:16:39 pm]
Offical launch of the 1 B...
by
Hartmut
[April 23, 2024, 04:49:29 pm]
what to do if my target M...
by
nickysn
[April 23, 2024, 04:16:02 pm]
compiler error in unit
by
paule32
[April 23, 2024, 03:49:50 pm]
Multithreading - synchron...
by
mika
[April 23, 2024, 01:48:51 pm]
May be useful to somebody
by
KodeZwerg
[April 23, 2024, 12:38:22 pm]
match automatic highlight...
by
Чебурашка
[April 23, 2024, 11:35:14 am]
Tchart with dual numbers ...
by
wp
[April 23, 2024, 10:48:18 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] Transparent TBGRABitmap copied/assigned to TImage loses transparency (Read 1205 times)
r.lukasiak
Full Member
Posts: 138
[SOLVED] Transparent TBGRABitmap copied/assigned to TImage loses transparency
«
on:
June 03, 2022, 05:52:27 am »
Hi everyone!
I need a semi-transparent dynamically generated image, I create it on TBGRABitmap but when I assign it to TImage, the Image has a black background.
Googling led me to this post
https://forum.lazarus.freepascal.org/index.php/topic,55300.msg411319.html#msg411319
. According to the author, the solution worked but in my case it didn't. I tested it on QT5 (Linux) and Windows, in both cases exactly the same result.
Code: Pascal
[Select]
[+]
[-]
var
bubble
:
Timage
;
bmp
:
TBGRABitmap
;
TBit
:
TBitmap
;
cc
:
integer
;
begin
cc
:
=
ChatsTab
.
ControlCount
;
bubble
:
=
Timage
.
Create
(
Self
)
;
bubble
.
Parent
:
=
ChatsTab
;
bubble
.
Width
:
=
ChatTab
.
ClientWidth
div
2
;
bubble
.
Height
:
=
60
;
bubble
.
Left
:
=
(
ChatsTab
.
ClientWidth
-
bubble
.
Width
)
div
2
;
bubble
.
top
:
=
10
+
cc
*
60
;
bubble
.
Picture
.
Bitmap
.
MaskHandle
:
=
0
;
bubble
.
Picture
.
Bitmap
.
Transparent
:
=
True
;
bubble
.
Picture
.
Bitmap
.
TransparentColor
:
=
$000000
;
TBit
:
=
TBitmap
.
Create
;
TBit
.
PixelFormat
:
=
pf24bit
;
TBit
.
Width
:
=
bubble
.
Width
;
TBit
.
Height
:
=
bubble
.
Height
;
bmp
:
=
TBGRABitmap
.
Create
(
bubble
.
Width
,
bubble
.
Height
,
BGRA
(
0
,
0
,
0
,
0
)
)
;
bmp
.
draw
(
TBit
.
Canvas
,
0
,
0
,
true
)
;
bmp
.
RoundRect
(
10
,
10
,
bubble
.
Width
-
10
,
bubble
.
Height
-
10
,
15
,
15
,
$00FF9900
,
BGRA
(
128
,
128
,
128
,
255
)
,
dmDrawWithTransparency
,
8192
)
;
bubble
.
picture
.
Assign
(
bmp
)
;
Any clue?
As a matter of fact I don't need specifically TImage, I need any way to display what I create on TBGRABitmap. Maybe someone can recommend any other component?
thanks in advance!
«
Last Edit: June 03, 2022, 06:20:57 pm by r.lukasiak
»
Logged
circular
Hero Member
Posts: 4221
Re: Transparent TBGRABitmap copied/assigned to TImage loses transparency
«
Reply #1 on:
June 03, 2022, 07:31:22 am »
Hi!
To be sure to have transparency, I suggest to use TBGRAGraphicControl of BGRAControls. In the redraw event, draw the content as you like using the Bitmap: TBGRABitmap parameter.
It also takes into account Retina scaling on MacOS (with BitmapAutoscale property).
Logged
Conscience is the debugger of the mind
r.lukasiak
Full Member
Posts: 138
Re: Transparent TBGRABitmap copied/assigned to TImage loses transparency
«
Reply #2 on:
June 03, 2022, 06:20:38 pm »
thank you very much for you answer.
I'd tried TBGRAGraphicControl but I can't get it to work, I don't know what I'm doing wrong. Anyway it requires painting OnRedraw which would complicate my code a little bit.
I've just found TBDRoundedImage, it works as needed, I just needed to switch rounding off.I just create it dynamically, draw what I need using TBGRABitmap and assign it to TBDRoundedImage as I tried with TImage.
thanks!
Logged
circular
Hero Member
Posts: 4221
Re: [SOLVED] Transparent TBGRABitmap copied/assigned to TImage loses transparency
«
Reply #3 on:
June 03, 2022, 06:46:43 pm »
I understand you're used to draw outside of the OnPaint event. Though in this case, I don't really see why this would be complicated. You can store some info on how to draw things in variables for example. Maybe you can find some help on how to do that.
But of course you're free to find the way it suits you.
Logged
Conscience is the debugger of the mind
r.lukasiak
Full Member
Posts: 138
Re: [SOLVED] Transparent TBGRABitmap copied/assigned to TImage loses transparency
«
Reply #4 on:
June 03, 2022, 10:10:29 pm »
well, I'm used to drawing in OnDraw but in my current case it'd be more difficult, every Image depends on some external data and they are created dynamically
And I didn't actually figure out how to draw on TBGRAGraphicControl, I tried a couple of days ago and then again today (after you mentioned it) but I didn't succeed. Maybe some sample code or some instructions? I'd really appreciate it.
thx
Logged
circular
Hero Member
Posts: 4221
Re: [SOLVED] Transparent TBGRABitmap copied/assigned to TImage loses transparency
«
Reply #5 on:
June 04, 2022, 08:18:49 am »
One approach would be to create a TBGRABitmap at the beginning (when the form is created for example). Then each time you need to draw, you draw in this bitmap. And in the OnRedraw event of TBGRAGraphicControl copy the bitmap.
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
FormCreate
(
Sender
:
TObject
)
;
begin
myBuffer
:
=
TBGRABitmap
.
Create
(
BGRAGraphicControl1
.
Width
,
BGRAGraphicControl1
.
Height
)
;
end
;
procedure
TForm1
.
FormDestroy
(
Sender
:
TObject
)
;
begin
myBuffer
.
Free
;
end
;
procedure
TForm1
.
BGRAGraphicControl1Redraw
(
Sender
:
TObject
;
Bitmap
:
TBGRABitmap
)
;
begin
Bitmap
.
PutImage
(
0
,
0
,
myBuffer
,
dmSet
)
;
end
;
procedure
TForm1
.
BGRAGraphicControl1MouseDown
(
Sender
:
TObject
;
Button
:
TMouseButton
;
Shift
:
TShiftState
;
X
,
Y
:
Integer
)
;
begin
myBuffer
.
FillEllipseAntialias
(
X
,
Y
,
6
,
6
,
clWindowText
)
;
BGRAGraphicControl1
.
DiscardBitmap
;
end
;
myBuffer
is a variable declared in the
class(TForm)
.
If the BGRAGraphicControl1 size changes, you need to determine how to change the size of myBuffer or if you want to stretch it when you draw it.
Logged
Conscience is the debugger of the mind
r.lukasiak
Full Member
Posts: 138
Re: [SOLVED] Transparent TBGRABitmap copied/assigned to TImage loses transparency
«
Reply #6 on:
June 06, 2022, 11:48:24 pm »
thank you very much! it works perfectly. I will use this approach, the RoundedImage is, for some reason, generating garbage when I use .TextOut function (I will create a separate post on it, it seems to be a bug).
once again, thanks for the example!
Logged
circular
Hero Member
Posts: 4221
Re: [SOLVED] Transparent TBGRABitmap copied/assigned to TImage loses transparency
«
Reply #7 on:
June 06, 2022, 11:49:52 pm »
You're welcome.
Sure, feel free to make a post if there is another issue or question.
Logged
Conscience is the debugger of the mind
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Graphics and Multimedia
»
Graphics
(Moderator:
Ask
) »
[SOLVED] Transparent TBGRABitmap copied/assigned to TImage loses transparency
TinyPortal
© 2005-2018