• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 784
  • Last Modified:

How to get the standard TransparentColor value back?

I am using the TransparentColor property of a glyph to switch off the transparency of an image.
To switch it off I set

Glyph.TransparentColor := clNone;

But how do I switch it on again? How to get the right color?
I have no clue how to get the previously set TransparentColor.
Glyph.Canvas.Pixels has other values.

0
Treppenmeister
Asked:
Treppenmeister
  • 8
  • 8
1 Solution
 
rfwoolfCommented:
Hmmm... you will have to find another way to disable transparency.
Typically, the top-left pixel in the image is reserved for the "Transparent Color" so that might help,
but otherwise you will have to store the transparent colour somewhere, or find another way of disabling transparency.
0
 
epasquierCommented:
rfwoolf : that's the bottom-left pixel that is used by default
"the color of the pixel in the picture's lower-left corner will be used as the transparent color. All the pixels of that color will be transparent, the button's surface will be visible at these spots."

Anyway, you have no choice but to save the TransparentColor value before putting clNone. You could save it in the button.Tag for example :

procedure SwitchTransparency(btn:TButton);
begin
 if btn.Glyph.TransparentColor =clNone 
  Then btn.Glyph.TransparentColor:= TColor(btn.Tag) Else
  begin
   btn.Tag:= Integer(btn.Glyph.TransparentColor);
   btn.Glyph.TransparentColor:= clNone;
  end;
end;

Open in new window

0
 
TreppenmeisterAuthor Commented:
I found now that the value clDefault could be the one i was looking for.
Is there a reason not to use that value?

the TTransparentMode will be changed from tmfix to tmauto
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
epasquierCommented:
I assumed the transparentmode should be tmFixed , as otherwise TransparentColor is not used. If you switch TransparentMode, then you will switch transparency color from the color specified in TransparentColor to/from the color in the bottom-Left corner of the image. Is that what you want or do you want to switch from No-Transparency to/from Transparent with color specified ?

"The Transparent property of a TBitmap works only if you use the Draw method to draw it on a canvas. If Transparent := TRUE, and TransparentMode := tmAuto, then the transparent color is the color of the bottom-leftmost pixel of the bitmap. If TransparentMode := tmFixed, then the transparent color is defined by the TransparentColor property."

I see no use of clDefault instead of clNone.
0
 
TreppenmeisterAuthor Commented:
I switch off the Transparency by setting
TransparentColor := clNone.
The TTransparentMode will automatically set to tmfix.

Till now i only switch off the transparency - switching it on was ignored. So I was looking now for a solution.

By setting tTransparentColor := clDefault it seems so whether the TTransparentMode is set back to tmfix.and the color of the left lower corner is used (this is the default setting?) instead of the value in tTransparentColor.

"I see no use of clDefault instead of clNone."

You mean that i should set only tTransparentMode instead?

But i have still no clue where from the originally value in tTransparentColor comes from.
0
 
epasquierCommented:
>> But i have still no clue where from the originally value in tTransparentColor comes from.

From the lower-left pixel of your image.

Setting TransparentMode:=tmAuto will use this pixel color again for transparency
0
 
epasquierCommented:
so, to summerize :

* Switch Off Transparency :
TransparentColor := clNone;
=> TransparentMode is automatically set to tmfix, as you found out

* Switch On Transparency to default color (bottom-left pixel)
TransparentMode := tmAuto;
=> TransparentColor is ignored

* Switch On transparency to another color
TransparentColor := AnotherColor;
=> TransparentMode is automatically set to tmfix

If that AnotherColor is a the color of a pixel you know in your image with X,Y position, you can access it with Transparent.Color:= bmp.Canvas.Pixels[X,Y];
0
 
TreppenmeisterAuthor Commented:
I thought so too - but the reality looks other.

I have a glyph with white edges - I get for

bmp.Canvas.Pixels[X,Y] the value FFFFFF

but the value of transparentcolor is 2FFFFF. So this value cannot be the color of the lower left pixel. It has to come from somewhere else.
0
 
epasquierCommented:
reality only LOOKS different
with TransparentMode = tmAuto, the VCL cannot have a magical algo deciding the transparent color for you if not by a simple rule always respected which is TransparentColor = "Bottom-Left Pixel" = Canvas.Pixels[0,Height-1]
Check the value of this bottom-left pixel, a common practice when you need a transparent glyph with square border, say 20x20 pixels, the image is 20x21 with the bottom line = transparent color
0
 
TreppenmeisterAuthor Commented:
I made now some more checks - depending on the glyph I get for TransparentColor the values
$2FFFF (8, 24 Bit)
or
$2BCBCBC  (32 Bit).

These colors do not exist in the glyph. So these has to be the default values.
But they do not exist as constants - what could be the reason why Borland didnt do it?

And it would also mean that for resetting to the default values I have to check whether it is a 32-Bit glyph or not :-(

And are these values fix or depending on the OS-settings?


0
 
TreppenmeisterAuthor Commented:
Do I make too many thoughts????

The case (TransparentMode = tmAuto) is uninteresting since it is clear what happens then.
But when i set only
TransparentMode := tmfix
then there is a different behaviour - depending whether i touched once the value TransparentColor or not. And this is what i didnt want. All this is very theoretically. I dont think that there will be ever a case (for me) that i switch between the different values again and again.
All i wanted is a clean programming, that i will be able to switch back the transparentcolor to the default value.
And this seems to be $2FFFFF (I forgot one F in the posting before)


0
 
TreppenmeisterAuthor Commented:
But then again Delphi is using 'clDefault = TColor($20000000)' - why i dont get these values from the beginning?
I give up :-(
0
 
epasquierCommented:
$2BCBCBC  is much different in essence : when the higher byte of a color is <>0 then it is not an RGB value

The internal format of TColor can have five formats:
1.  $00bbggrr -- Create using the RGB function
2.  $010000nn -- Create using the PaletteIndex function
3.  $02bbggrr -- Create using the PaletteRGB function
4.  $800000nn -- Defined in Graphics.PAS using Windows constants COLOR_SCOLLBAR, etc.  These negative values must be passed to the ColorToRGB function to have R, G and B components defined.
5. The fifth is a very special case not worth getting into

I suspect you forgot again an F in what should be $02 FF FF FF => closest value to pure white in the current windows palette

I tested, by default TransparentColor is set to the closest entry in windows palete if the bottom-left pixel, which means it starts with $02BBGGRR.

You can use ColorToRGB function to convert any coded TColor to the equivalent RGB value (in 32 bit windows display mode, it will only strip the $02 in the higher byte)

so, to answer this : Do I make too many thoughts????
> probably, yes
> but as long as you are trying to figure some new things out and learning, it's ok to be
for example, I tested with 2 images :
        BottomLeft Pixel        TransparentColor
Glyph1 : 00 C0C0C0                   02 C0C0C0   
Glyph2 : 00 F5E6B9                   02 F5E6B9

Open in new window

0
 
epasquierCommented:
> clDefault = TColor($02 00 00 00)  // I think you added a 0 here
which means, the default color is the closest to white in windows palette, whatever display mode you are in.
0
 
TreppenmeisterAuthor Commented:
Ouch - I should learn to read properly :-(

I really forgot the one F (2 FF FF FF instead of 2F FF FF) - but i wrote it so wrong on my notes - and never questioned it again. And then i was only checking how the TransparentColor was changing.
What a waste of time :-(
But my biggest mistake was certainly that i was trying to compare 2 different types of tColor (0 and 2).

At least I learnt some new things. Thank you very much - also for taking the time.

Is there an internal function that i can use to compare 'blind' the different types of tColor with each other? Or do i have always manually ignore that $02 at the beginning?

0
 
epasquierCommented:
yes, ColorToRGB will translate any TColor format into $00BBGGRR format.

To check 2 colors are equal, you then use
ColorToRGB(Color1)=ColorToRGB(Color2)
0
 
TreppenmeisterAuthor Commented:
"Please Address Your Abandoned Question..."

I just came back from holiday. I need still some time before i close it.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now