Board index » delphi » Transparent Bitmap

Transparent Bitmap


2003-07-28 04:02:37 PM
delphi2
Hi, I am new to graphic programming and have a limited skill in this area and
require some help. I got hold of a component called TBSMorphButton and it
seems cool and was the only morphbutton available for me to use (unless
someone else can recomend others and I'd be even happier). I have been
changing his code to suite my needs and bump into something rather difficult
for my ability.
I wish to make it transparent. At first I manage to handle it by using
TBitmap.Transparent := True and it seems to have solve the case, but then in
9x, it didn't morph so nicely anymore. It flickers in black everytime it
morph. Could anyone teach me any other ways to transparent a TBitmap. I'm
thinking that maybe mask might do the trick but don't konw how to implement
it. CoolButton seems to be using this API call ImageList_DrawEx() but I'm
only using bitmap. Does anyone else have better suggestion?
 
 

Re:Transparent Bitmap

Hi,
Really simple question here: How do you paint a bitmap to a canvas with a
transparent colour?
Thanks,
Gregory Haynes
 

Re:Transparent Bitmap

Something like this. Use code completion for the exact code.
TBitmap.transparent := true;
TBitmap.transparencycolor := ClRed;
"Gregory Haynes" <XXXX@XXXXX.COM>writes
Quote
Hi,

Really simple question here: How do you paint a bitmap to a canvas with a
transparent colour?

Thanks,
Gregory Haynes


 

Re:Transparent Bitmap

Hi,
I'm activating Flash Player from C++ to draw Flash movies on the
screen. When I am trying to draw the Flash movie in transparent window I
encounter the following problem:
- In 32bit it works fine.
- In 16Bit (High Color) , and 256 Color it doesn't work as it was
expected.
Please see below my code that handle this issue:
void CFlashWindow::HandleWindowlessPaint()
{
BLENDFUNCTION blend;
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
blend.SourceConstantAlpha = 255;
blend.AlphaFormat = AC_SRC_ALPHA;
// window size
RECT r;
GetClientRect(m_hwnd, &r);
SIZE NewWinSize = {r.right-r.left, r.bottom-r.top};
HDC hdc = GetDC(0);
HDC hdcOff = CreateCompatibleDC(hdc);
BITMAPINFOHEADER bmih;
VOID * pBits;
ZeroMemory(&bmih, sizeof(bmih));
bmih.biSize = sizeof (BITMAPINFOHEADER) ;
bmih.biWidth = NewWinSize.cx;
bmih.biHeight = NewWinSize.cy;
bmih.biPlanes = 1;
bmih.biBitCount = 32;//8; //32;
bmih.biCompression = BI_RGB;
HBITMAP hbm = CreateDIBSection (NULL, (BITMAPINFO *) &bmih, 0,
&pBits, NULL, 0) ;
HGDIOBJ tempObj = SelectObject(hdcOff, hbm);
Draw(hdcOff);
// New window pos
POINT NewWinPos = {0,0};
ClientToScreen(m_hwnd, &NewWinPos);
// New layer pos
POINT LayerPos = {0,0};
if (UpdateLayeredWindow( m_hwnd, hdc, &NewWinPos, &NewWinSize, hdcOff,
&LayerPos, RGB(0,0,0), &blend, ULW_ALPHA) == 0) {
LPVOID lpMsgBuf;
int gle = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
gle,
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL );
char* t = (char*)lpMsgBuf;
}
SelectObject(hdcOff, tempObj);
DeleteObject(hbm);
DeleteDC(hdcOff);
ReleaseDC(0, hdc);
}
Can you please help me fixing this problem. I am not a GDI expert, so if
you can fix the code it will be helpfully.
Thanks,
Robert
 

Re:Transparent Bitmap

I'm trying to display successive rotated transparent bitmap on a TPaintBox,
and that leaves traces...
How not to...?
DH
 

Re:Transparent Bitmap

"David HAROUCHE" <XXXX@XXXXX.COM>writes
Quote
I'm trying to display successive rotated transparent bitmap on a
TPaintBox, and that leaves traces...
It leaves traces? Do you mean like fingerprints and DNA evidence?
 

Re:Transparent Bitmap

Yes, Scotland Yard just went out after my call and they say they just don't
understand...
Sherlock Holmes is now on the stage : refreshing the TPaintBox. after a
canvas.Draw with a modified bitmap leaves some foot prints...
Should I take a snapshot of what is under ...?
DH
 

Re:Transparent Bitmap

GrandmasterB writes:
Quote
"David HAROUCHE" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>Sherlock Holmes is now on the stage : refreshing the TPaintBox.
>after a canvas.Draw with a modified bitmap leaves some foot
>prints...
>
>Should I take a snapshot of what is under ...?

It's elementary, my dear Watson... clear the canvas before you do the
paint. Then no evidence will be left behind.
Dear Sherlock, you really don't get it, do you. He wants to be caught
and therefor leave some traces behind. ;-)
--
Pieter
 

Re:Transparent Bitmap

It looks like your algorithm to transform (rotate) the bitmap doesn't set
all destination pixels correctly. You might look at that. Graphics32 has
some good code.
Nils
"David HAROUCHE" <XXXX@XXXXX.COM>schreef in bericht
Quote
I'm trying to display successive rotated transparent bitmap on a
TPaintBox, and that leaves traces...

How not to...?

DH

 

Re:Transparent Bitmap

Quote
>Clear the canvas before you do the paint.
Clearing ?
how ?
Quote
>Then no evidence will be left behind.
Did you engaged Alfred Hitchcock ?
DH
 

Re:Transparent Bitmap

"David HAROUCHE" <XXXX@XXXXX.COM>writes
Quote
>>Clear the canvas before you do the paint.
Clearing ?
how ?
Its going to depend on what it is you are specifically doing. But in
general, draw a rectangle over the canvas with the background color. Then
draw your background image. Then draw your bitmap rotated at its new angle.
 

Re:Transparent Bitmap

Quote
>Its going to depend on what it is you are specifically doing.
I just try to use bitmap.Transparent efficiently when I draw successives
images on a TPaintBox located on a TForm that is Transparent...!!!
Quote
>But in general, draw a rectangle
You surely mean canvas.FillRect !
Quote
>Then draw your background image.
Thats' where I think about a snapshot of the desktop of what is under the
TPaintBox...! But what if a change occurs on the desktop ?
Quote
>Then draw your bitmap rotated at its new angle.
That causes more flickers on screen...
DH
 

Re:Transparent Bitmap

"David HAROUCHE" <XXXX@XXXXX.COM>writes
Quote
>>But in general, draw a rectangle
You surely mean canvas.FillRect !
No - I mean what I say, and say what I mean!
And what I mean is draw a rectangle over the background, regardless of what
graphics interface you are using. If you are using vcl drawing routines,
then fillrect will do. I personally dont use the vcl routines much, so am
more likely to use native gdi calls or gdi+ methods.
Quote
>>Then draw your bitmap rotated at its new angle.
That causes more flickers on screen...
Then it sounds to me your real problem is flickering. I'd focus on
fixing that.
 

Re:Transparent Bitmap

Quote
>Then it sounds to me your real problem is flickering.
I started another thread...
;)
DH