Alaska Software Inc. - :getDefaultBgColor()
Username: Password:
AuthorTopic: :getDefaultBgColor()
Carlos a Beling :getDefaultBgColor()
on Tue, 05 Jun 2018 15:27:45 -0300
Hello.
Good afternoon.
How to set the XbpBitmap():defaultBGColor()?

Fraternally
Beling
Andreas Gehrs-Pahl
Re: :getDefaultBgColor()
on Tue, 05 Jun 2018 18:34:14 -0400
Carlos,

>How to set the XbpBitmap():defaultBGColor()?

Either directly, with:

	oBitmap:TransparentClr := nColor

Or indirectly, by setting the Pixel at Position {1, 1} (top left of the 
image) to the color you want to use. But that will change the content of 
your image, so it doesn't make much sense to do this, especially if you can 
set this color directly (see above).

When a bitmap (file) is loaded, Xbase++ sets the :TransparentClr instance 
variable to either GRA_CLR_INVALID (-6) or the actual Transparent Color 
that is defined in the image file. This only works for GIF and PNG files, 
which can (but might not) contain a Transparent Color value.

The :GetDefaultBGColor() method returns the color of the first (top left) 
pixel of the image, or in case of an error, GRA_CLR_INVALID. That color can 
then be used to set the :TransparentClr iVar, if you like.

But this doesn't mean that it is a good idea to use that particular color 
value as the Transparent (or Background Masking) Color!

Also, most graphics programs only use Background Masking (displaying an 
image with a transparent background color) if the Transparent Color was 
specifically set in the GIF or PNG file, so setting the top left pixel to 
a specific color has usually no effect on the transparency of an image.

Hope that helps,

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[F]:   https://www.facebook.com/AbsoluteSoftwareLLC
Carlos a Beling Re: :getDefaultBgColor()
on Wed, 06 Jun 2018 10:59:15 -0300
Hello Andreas:
good morning.
Many thanks again.

Here is my trouble:
1) I created one XbpBitmap() in memory (saved here as Original.ico)
2) in some cases I want the BG green to be shown as transparent and when 
I do oBitmap:transparentClr := GramakeRGBcolor({0, 255, 0}) it is 
rendered as the attached image Strange.ico. The XbpBitmap() foreground 
color is GraMakeRGBColor({ 40, 25, 115}).
Does it has an way to render the XbpBitmap() with the correct FG color?

Fraternally
Beling


Em 05/06/2018 19:34, Andreas Gehrs-Pahl escreveu:
> Carlos,
>
>> How to set the XbpBitmap():defaultBGColor()?
>
> Either directly, with:
>
> 	oBitmap:TransparentClr := nColor
>
> Or indirectly, by setting the Pixel at Position {1, 1} (top left of the
> image) to the color you want to use. But that will change the content of
> your image, so it doesn't make much sense to do this, especially if you can
> set this color directly (see above).
>
> When a bitmap (file) is loaded, Xbase++ sets the :TransparentClr instance
> variable to either GRA_CLR_INVALID (-6) or the actual Transparent Color
> that is defined in the image file. This only works for GIF and PNG files,
> which can (but might not) contain a Transparent Color value.
>
> The :GetDefaultBGColor() method returns the color of the first (top left)
> pixel of the image, or in case of an error, GRA_CLR_INVALID. That color can
> then be used to set the :TransparentClr iVar, if you like.
>
> But this doesn't mean that it is a good idea to use that particular color
> value as the Transparent (or Background Masking) Color!
>
> Also, most graphics programs only use Background Masking (displaying an
> image with a transparent background color) if the Transparent Color was
> specifically set in the GIF or PNG file, so setting the top left pixel to
> a specific color has usually no effect on the transparency of an image.
>
> Hope that helps,
>
> Andreas
>


Original.ico
Strange.ico
Andreas Gehrs-Pahl
Re: :getDefaultBgColor()
on Wed, 06 Jun 2018 17:05:38 -0400
Carlos,

>Here is my trouble:
>1) I created one XbpBitmap() in memory (saved here as Original.ico)
>2) in some cases I want the BG green to be shown as transparent and when 
>I do oBitmap:transparentClr := GramakeRGBcolor({0, 255, 0}) it is 
>rendered as the attached image Strange.ico. The XbpBitmap() foreground 
>color is GraMakeRGBColor({ 40, 25, 115}).

Take a look at this web page:

   https://en.wikipedia.org/wiki/Transparency_(graphic)#Transparent_pixels

It explains the issue that you have: see the three "Chapter One" example 
images on the right side.

>Does it has an way to render the XbpBitmap() with the correct FG color?

Simply put, it does render "correctly".

I would suggest that the whole idea of saving some text that was printed 
with Gra*() functions (I assume) as an Icon file (with a transparent color) 
is a very bad idea. The only way to do this correctly would be with partial 
transparency (or translucency) using Alpha Channels, but I don't know if 
icon files support Alpha Channels or how to make the Gra*() functions use 
partial transparency.

Hope that explains it,

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[F]:   https://www.facebook.com/AbsoluteSoftwareLLC
Carlos a Beling Re: :getDefaultBgColor()
on Thu, 07 Jun 2018 11:21:51 -0300
Helo Andreas.
Good morning
Many thanks again.
I will correct the bad things that I did.
I will give a try to xbpBitmap():transparency for to see if it works.

Fraternally
Beling

Em 06/06/2018 18:05, Andreas Gehrs-Pahl escreveu:
> Carlos,
>
>> Here is my trouble:
>> 1) I created one XbpBitmap() in memory (saved here as Original.ico)
>> 2) in some cases I want the BG green to be shown as transparent and when
>> I do oBitmap:transparentClr := GramakeRGBcolor({0, 255, 0}) it is
>> rendered as the attached image Strange.ico. The XbpBitmap() foreground
>> color is GraMakeRGBColor({ 40, 25, 115}).
>
> Take a look at this web page:
>
>     https://en.wikipedia.org/wiki/Transparency_(graphic)#Transparent_pixels
>
> It explains the issue that you have: see the three "Chapter One" example
> images on the right side.
>
>> Does it has an way to render the XbpBitmap() with the correct FG color?
>
> Simply put, it does render "correctly".
>
> I would suggest that the whole idea of saving some text that was printed
> with Gra*() functions (I assume) as an Icon file (with a transparent color)
> is a very bad idea. The only way to do this correctly would be with partial
> transparency (or translucency) using Alpha Channels, but I don't know if
> icon files support Alpha Channels or how to make the Gra*() functions use
> partial transparency.
>
> Hope that explains it,
>
> Andreas
>
Itai Ben-ArtziRe: :getDefaultBgColor()
on Thu, 26 Jul 2018 00:16:47 -0700
>Carlos,
>You may achieve the effect you want by "cheating" as follow:
>***************************
>cFileGIF := dtos(date())+'.gif'
>cFilePNG := dtos(date())+'.png'
>
>oBitmap := XbpBitmap():New():create()
>obitmap:loadfile(cFileName)
>xTemp := oBitmap:GetDefaultBGColor()
>oBitmap:TransparentClr := xTemp    Set the background color transparent.
>oBitmap:transparency   := 255          Set the transparency level (0-255)
>oBitmap:saveFile( cFileGIF, XBPBMP_FORMAT_GIF )   Create a GIF transparent (we should not save as PNG because Alaska poorly handles PNG format).
>
>// if you need it as PNG, use WIA to convert
>CreatePNG( cFileGIF, cFilePNG )
>
>// Load the PNG
>oBitmap :Destroy()
>oBitmap := XbpBitmap():New():create()
>obitmap:loadfile(cFilePNG)
>*****************************
>
>I call it cheating because the image is not truly transparent (hasAlphaChannel = .F., Bits <> 32, transparency = 0), but the draw() simulate a transparent image.
>
> -Itai
Carlos a Beling Re: :getDefaultBgColor()
on Thu, 26 Jul 2018 10:54:54 -0300
Hello Itai.
Good morning.
Unfortunately I do not understanding how to work with images. The sample 
of Mr Diego worked for me.
Observe that:
	. oBitmap:transparency defines the transparence of all image not the 
transparent colour and it only works when used before gthe :draw() method.
	. the image for to be converted was first saved as  oBitmap:saveFile( 
cFile, XBPBMP_FORMAT_WIN3X )

Fraternally
Beling

Em 26/07/2018 04:16, Itai Ben-Artzi escreveu:
>> Carlos,
>> You may achieve the effect you want by "cheating" as follow:
>> ***************************
>> cFileGIF := dtos(date())+'.gif'
>> cFilePNG := dtos(date())+'.png'
>>
>> oBitmap := XbpBitmap():New():create()
>> obitmap:loadfile(cFileName)
>> xTemp := oBitmap:GetDefaultBGColor()
>> oBitmap:TransparentClr := xTemp    Set the background color transparent.
>> oBitmap:transparency   := 255          Set the transparency level (0-255)
>> oBitmap:saveFile( cFileGIF, XBPBMP_FORMAT_GIF )   Create a GIF transparent (we should not save as PNG because Alaska poorly handles PNG format).
>>
>>  if you need it as PNG, use WIA to convert
>> CreatePNG( cFileGIF, cFilePNG )
>>
>>  Load the PNG
>> oBitmap :Destroy()
>> oBitmap := XbpBitmap():New():create()
>> obitmap:loadfile(cFilePNG)
>> *****************************
>>
>> I call it cheating because the image is not truly transparent (hasAlphaChannel = .F., Bits <> 32, transparency = 0), but the draw() simulate a transparent image.
>>
>> -Itai