joely
asked on
TLabel : Semi Transparent
How to make semi transparent of label ?
Maybe older versions of Delphi don't have the Transparent property??? In that case, you can write onto any canvas without erasing the background as follows:
SetBkMode(ACanvas.Handle, TRANSPARENT);
ACanvas.TextOut(2, 2, 'This is transparent text.');
SetBkMode(ACanvas.Handle, OPAQUE);
Regards,
JB
SetBkMode(ACanvas.Handle, TRANSPARENT);
ACanvas.TextOut(2, 2, 'This is transparent text.');
SetBkMode(ACanvas.Handle, OPAQUE);
Regards,
JB
Do you want semitransparent text or background or both?
Either way you will have to work with an intermediate bitmap and some pixel-twiddling...
/// John
Either way you will have to work with an intermediate bitmap and some pixel-twiddling...
/// John
if its a component, then this will work (should).
ControlStyle := ControlStyle - [csOpaque];
ControlStyle := ControlStyle - [csOpaque];
I think JimBob's answer is OK
ASKER
Thank you for your comment.
I want try to explain about "semi" transparent.
If I have a background (using TImage) and I put a label (the color property filled with black color) in the front of TImage.
If Transparent property is True so the black color will lost.
"Semi" I mean, we are still look the background through a label but the black color not lost.
I give the example if we want to shutdown Windows or if you know Eidos's Championship Manager (Soccer Games Strategy).
Thank you.
I want try to explain about "semi" transparent.
If I have a background (using TImage) and I put a label (the color property filled with black color) in the front of TImage.
If Transparent property is True so the black color will lost.
"Semi" I mean, we are still look the background through a label but the black color not lost.
I give the example if we want to shutdown Windows or if you know Eidos's Championship Manager (Soccer Games Strategy).
Thank you.
Do you simply want dithering or true semitransparence?
When Windows shuts down it uses $AA$55 dithering.
/// John
When Windows shuts down it uses $AA$55 dithering.
/// John
Note: true semitransparence looks best in hi- to true-color modes and can be difficult to achieve in 16-32768 color modes.
Dithering can be made quite goodlooking in any mode (2-48 bit).
/// John
Dithering can be made quite goodlooking in any mode (2-48 bit).
/// John
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Quite a good solution. Terribly slow though.
If you, joely, confirm this to be the semitransparence you're looking for, I might just send you some pointers on how to make it faster.
/// John
If you, joely, confirm this to be the semitransparence you're looking for, I might just send you some pointers on how to make it faster.
/// John
ASKER
How to make it faster ?
Sorry it took me so long.
I didn't remember the quick way last night. This is the fast method (Windows API). The effect property doesn't nee to be published, but it gives the component a lot more usability.
Try this instead:
unit STLabel;
interface
uses
Windows, Classes, StdCtrls;
type
TEffect=(teBlackness,teDST Invert,teM ergeCopy,t eMergePain t,teNotSRC Copy,
teNotSRCErase,tePATCopy,te PATInvert, tePATPaint ,teSRCAnd, teSRCCopy,
teSRCErase,teSRCInvert,teS RCPaint,te Whiteness) ;
TSTLabel = class(TLabel)
private
fEffect:TEffect;
protected
procedure Paint; Override;
procedure SetEffect(Value:TEffect);
public
constructor Create(AOwner:TComponent); override;
published
property Effect:TEffect read fEffect write SetEffect;
end;
procedure Register;
implementation
uses Graphics;
const Effects:array[TEffect] of Integer=(BLACKNESS,DSTINVE RT,MERGECO PY,
MERGEPAINT,NOTSRCCOPY,NOTS RCERASE,PA TCOPY,PATI NVERT,PATP AINT,
SRCAND,SRCCOPY,SRCERASE,SR CINVERT,SR CPAINT,WHI TENESS);
constructor TSTLabel.Create(AOwner:TCo mponent);
begin
inherited Create(AOwner);
Transparent:=True;
fEffect:=teSRCPaint;
end;
procedure TSTLabel.Paint;
var Bmp1:TBitmap;
begin
Bmp1:=TBitmap.Create;
Bmp1.width:=Width;
Bmp1.Height:=Height;
Bmp1.Canvas.Brush.Style:=b sSolid;
Bmp1.Canvas.Brush.Color:=C olor;
Bmp1.Canvas.FillRect(Rect( 0,0,Width, Height));
BitBLT(Bmp1.Canvas.Handle, 0,0,Width, Height,Can vas.Handle ,0,0,Effec ts[fEffect ]);
Canvas.Draw(0,0,Bmp1);
inherited;
end;
procedure TSTLabel.SetEffect(Value:T Effect);
begin
if fEffect<>Value then
begin
fEffect:=Value;
Refresh;
end;
end;
procedure Register;
begin
RegisterComponents('Sample s', [TSTLabel]);
end;
end.
I didn't remember the quick way last night. This is the fast method (Windows API). The effect property doesn't nee to be published, but it gives the component a lot more usability.
Try this instead:
unit STLabel;
interface
uses
Windows, Classes, StdCtrls;
type
TEffect=(teBlackness,teDST
teNotSRCErase,tePATCopy,te
teSRCErase,teSRCInvert,teS
TSTLabel = class(TLabel)
private
fEffect:TEffect;
protected
procedure Paint; Override;
procedure SetEffect(Value:TEffect);
public
constructor Create(AOwner:TComponent);
published
property Effect:TEffect read fEffect write SetEffect;
end;
procedure Register;
implementation
uses Graphics;
const Effects:array[TEffect] of Integer=(BLACKNESS,DSTINVE
MERGEPAINT,NOTSRCCOPY,NOTS
SRCAND,SRCCOPY,SRCERASE,SR
constructor TSTLabel.Create(AOwner:TCo
begin
inherited Create(AOwner);
Transparent:=True;
fEffect:=teSRCPaint;
end;
procedure TSTLabel.Paint;
var Bmp1:TBitmap;
begin
Bmp1:=TBitmap.Create;
Bmp1.width:=Width;
Bmp1.Height:=Height;
Bmp1.Canvas.Brush.Style:=b
Bmp1.Canvas.Brush.Color:=C
Bmp1.Canvas.FillRect(Rect(
BitBLT(Bmp1.Canvas.Handle,
Canvas.Draw(0,0,Bmp1);
inherited;
end;
procedure TSTLabel.SetEffect(Value:T
begin
if fEffect<>Value then
begin
fEffect:=Value;
Refresh;
end;
end;
procedure Register;
begin
RegisterComponents('Sample
end;
end.
ASKER
1. Effect property with teSRCPaint is not working for black color. Why is that?
2. How to reduce color intensity (using teSRCPaint because I think this effect better than the other, espesially for red and blue color). What I mean is this component will be more transparent so the background will be more visible.
2. How to reduce color intensity (using teSRCPaint because I think this effect better than the other, espesially for red and blue color). What I mean is this component will be more transparent so the background will be more visible.
Hi joley
1.- The component is doing an or function and black is 0. Try using SRCAND and an almost white instead;
2.- Change the color. What you do using SRCPAINT is to increase a particular color. If you choose clRed (That's RGB (255,0,0)) It will look red. Try the color RGB(216,0,0) or even lower. For Delphi clRed is $000000FF, clGreen id $0000FF00 and clBlue is $00FF0000.
Ok, here you can find what Delphi says the effects do:
Value Description
BLACKNESS Fills the destination rectangle using the color associated with index 0 in the physical palette. (This color is black for the default physical palette.)
DSTINVERT Inverts the destination rectangle.
MERGECOPY Merges the colors of the source rectangle with the specified pattern by using the Boolean AND operator.
MERGEPAINT Merges the colors of the inverted source rectangle with the colors of the destination rectangle by using the Boolean OR operator.
NOTSRCCOPY Copies the inverted source rectangle to the destination.
NOTSRCERASE Combines the colors of the source and destination rectangles by using the Boolean OR operator and then inverts the resultant color.
PATCOPY Copies the specified pattern into the destination bitmap.
PATINVERT Combines the colors of the specified pattern with the colors of the destination rectangle by using the Boolean XOR operator.
PATPAINT Combines the colors of the pattern with the colors of the inverted source rectangle by using the Boolean OR operator. The result of this operation is combined with the colors of the destination rectangle by using the Boolean OR operator.
SRCAND Combines the colors of the source and destination rectangles by using the Boolean AND operator.
SRCCOPY Copies the source rectangle directly to the destination rectangle.
SRCERASE Combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator.
SRCINVERT Combines the colors of the source and destination rectangles by using the Boolean XOR operator.
SRCPAINT Combines the colors of the source and destination rectangles by using the Boolean OR operator.
WHITENESS Fills the destination rectangle using the color associated with index 1 in the physical palette. (This color is white for the default physical palette.)
1.- The component is doing an or function and black is 0. Try using SRCAND and an almost white instead;
2.- Change the color. What you do using SRCPAINT is to increase a particular color. If you choose clRed (That's RGB (255,0,0)) It will look red. Try the color RGB(216,0,0) or even lower. For Delphi clRed is $000000FF, clGreen id $0000FF00 and clBlue is $00FF0000.
Ok, here you can find what Delphi says the effects do:
Value Description
BLACKNESS Fills the destination rectangle using the color associated with index 0 in the physical palette. (This color is black for the default physical palette.)
DSTINVERT Inverts the destination rectangle.
MERGECOPY Merges the colors of the source rectangle with the specified pattern by using the Boolean AND operator.
MERGEPAINT Merges the colors of the inverted source rectangle with the colors of the destination rectangle by using the Boolean OR operator.
NOTSRCCOPY Copies the inverted source rectangle to the destination.
NOTSRCERASE Combines the colors of the source and destination rectangles by using the Boolean OR operator and then inverts the resultant color.
PATCOPY Copies the specified pattern into the destination bitmap.
PATINVERT Combines the colors of the specified pattern with the colors of the destination rectangle by using the Boolean XOR operator.
PATPAINT Combines the colors of the pattern with the colors of the inverted source rectangle by using the Boolean OR operator. The result of this operation is combined with the colors of the destination rectangle by using the Boolean OR operator.
SRCAND Combines the colors of the source and destination rectangles by using the Boolean AND operator.
SRCCOPY Copies the source rectangle directly to the destination rectangle.
SRCERASE Combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator.
SRCINVERT Combines the colors of the source and destination rectangles by using the Boolean XOR operator.
SRCPAINT Combines the colors of the source and destination rectangles by using the Boolean OR operator.
WHITENESS Fills the destination rectangle using the color associated with index 1 in the physical palette. (This color is white for the default physical palette.)
What do you mean by "semi" transparent?
JB