BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

BMP and transparency

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
José
Guest





PostPosted: Sat Apr 21, 2007 8:54 pm    Post subject: BMP and transparency Reply with quote



Dear fellow programmers

I use a TImage to display BMP pictures, and the property Transparent
is true.

This appears to be silly, since everyone knows that BMP cannot be
transparent. OTOH the help files says that the Transparent property
only works if the picture contains a bitmap. (Bitmap is the same as
BMP, right?)

Anyhow, it works as I want. Perhaps there is a non documented thing in
my BMP files for transparency.

However, sometimes the wrong colour is made transparent. I searched
some time, and this is what I discovered:

TImage checks the bit in the lower left corner of the picture and uses
its colour to determine which colour must be transparent.

Can anyone confirm this?
--
José
Back to top
Miguel Gimenez
Guest





PostPosted: Sun Apr 22, 2007 2:30 am    Post subject: Re: BMP and transparency Reply with quote



José wrote:
Quote:
Dear fellow programmers

I use a TImage to display BMP pictures, and the property Transparent
is true.

This appears to be silly, since everyone knows that BMP cannot be
transparent. OTOH the help files says that the Transparent property
only works if the picture contains a bitmap. (Bitmap is the same as
BMP, right?)

Anyhow, it works as I want. Perhaps there is a non documented thing in
my BMP files for transparency.

However, sometimes the wrong colour is made transparent. I searched
some time, and this is what I discovered:

TImage checks the bit in the lower left corner of the picture and uses
its colour to determine which colour must be transparent.

Can anyone confirm this?

You can see the help for TBitmap::TransparentMode and
TBitmap::TransparentColor properties. If the first is set to tmAuto, the
second takes the value of the bottom left pixel (except as stated in the
help file). If you set the second, the first takes the value tmFixed.

Regards
Miguel Giménez
Back to top
JD
Guest





PostPosted: Sun Apr 22, 2007 7:48 am    Post subject: Re: BMP and transparency Reply with quote



José <jose (AT) 127 (DOT) 0.0.1> wrote:
Quote:

I use a TImage to display BMP pictures,

That is usually the wrong way to go ... especially when one
considers transparency.

Quote:
This appears to be silly, since everyone knows that BMP
cannot be transparent.

It is not that the BMP is transparent but rather that
it's rendering is which is not silly as evidenced by
your application of such.

Quote:
[...] Can anyone confirm this?

Yes, TBitmap looks at the lower / left pixel but I would
suggest to you that you're better off rendering the image
yourself because you can do it faster and have a greater
range of opacity in doing so.

~ JD
Back to top
José
Guest





PostPosted: Sun Apr 22, 2007 4:30 pm    Post subject: Re: BMP and transparency Reply with quote

On Sat, 21 Apr 2007 23:30:48 +0200, Miguel Gimenez <me (AT) privacy (DOT) net>
wrote in borland.public.cppbuilder.graphics:

Quote:
You can see the help for TBitmap::TransparentMode and
TBitmap::TransparentColor properties. If the first is set to tmAuto, the
second takes the value of the bottom left pixel (except as stated in the
help file). If you set the second, the first takes the value tmFixed.

Yes it's there! As usual, things are in the help file but they are
hard to find. and now I see that it is also possible to select a
colour which must be the transparent one.

I was rather pleased because my pictures were transparent, just as I
wanted, but I was troubled because a few pictures did not behave well,
in an unprdictable way. I tried everything until I discovered that all
misbehaving pictures had some stuff in the lower right corner.
--
José
Back to top
José
Guest





PostPosted: Sun Apr 22, 2007 4:31 pm    Post subject: Re: BMP and transparency Reply with quote

On 21 Apr 2007 19:48:25 -0700, "JD" <nospam (AT) nospam (DOT) com> wrote in
borland.public.cppbuilder.graphics:

Quote:
I use a TImage to display BMP pictures,

That is usually the wrong way to go ... especially when one
considers transparency.

And what is the right way?
--
José
Back to top
Bruce Larrabee
Guest





PostPosted: Mon Apr 23, 2007 1:30 pm    Post subject: Re: BMP and transparency Reply with quote

Hi JD,

I've messed around with this and related issues
also. Sometimes with variable degrees of success.

I'd too would be interested in any tips and insight
you could provide.

Bruce
Back to top
JD
Guest





PostPosted: Mon Apr 23, 2007 5:53 pm    Post subject: Re: BMP and transparency Reply with quote

José <jose (AT) 127 (DOT) 0.0.1> wrote:
Quote:

That is usually the wrong way to go ... especially when one
considers transparency.

And what is the right way?

Besides, the overhead associated with TImage, it's very slow
because as you change each pixel, it repaints the entire glyph
and it's not a TWinControl descendent so there is no handle
to use to disable refresh.

Don't get me wrong, it's ok for some usage but I would prefere
working with a TPanel or a TPaintBox and a TBitmap or just a
TBitmap (that depends on your application and what it is that
you're trying to accomplish). Of course, this means that you
have to assume responsibilty for rendering the image but in
most cases that's a single call to TCancas::CopyRect or the
win32 API BitBlt which are the fastest methods available.

TPanel has a Paint method and TPaintBox has an OnPaint event
but since I don't have a clue how you're actually using image
transparency, I can only speak in generalities.

The basic steps are that you load the bitmap and then size a
second bitmap to match the first. Then use the win32 API
BitBlt to grab a copy of the screen where the image will go
and place it in the second bitmap.

Then all you need to do is iterate the pixels in each bitmap
and compare them to determine what the pixel value should be
to get the desired results.

It may seems like *alot* more work and it is but the code is
faster and more flexable. The following link demonstrates
how to but it doesn't compare to determine transparancy but
rather it creates an opaque image by combining a portion of
the screen with the bitmap.

http://newsgroups.borland.com/cgi-bin/dnewsweb?cmd=article&group=borland.public.cppbuilder.graphics&item=29523&utag=

Note the use of the scan lines instead of pixel[x][y] and that the code for using the scan lines is different for different formats of a bitmap.

~ JD
Back to top
JD
Guest





PostPosted: Mon Apr 23, 2007 5:55 pm    Post subject: Re: BMP and transparency Reply with quote

Bruce Larrabee <bruce_l (AT) westbrookent (DOT) com> wrote:
Quote:

[...] I'd too would be interested in any tips and insight
you could provide.

Please see my last reply to José. If that doesn't help, you'll
need to ask a more specific question.

~ JD
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.