 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Peter Guest
|
Posted: Fri Mar 09, 2007 8:57 pm Post subject: smooth / transparent / blending edges splash screen - XP and |
|
|
Hi,
Using BCB5
I have a splash screen and the edges are made transparent by some code (or
link to it) posted here once.
Basically I convert one colour to transparent from a bmp picture loaded in a
TImage object.
(http://codeguru.earthweb.com/bitmap/bmp_to_rgn.shtml)
I would like to make this look a bit nicer on XP and VISTA systems, with
smooth / transparent / blending edges.
Now it's rather pixelated and not that nice depending on the background.
I'm thinking of finding some help to do it for me as I imagine some cleaning
up will need to be done on the picture itself etc.
But before I do that I would like to understand what it entails.
For starters, is it all possible to create the effect I wish from a bmp for
which on colour is made transparent ?
Or is there more to it and will I also need to change the code that converts
this one colour ?
Or will a bmp not do and do I need something else ?
Not sure I picked the right NG but it's a start.
Thanks for what intel you can share. |
|
| Back to top |
|
 |
JD Guest
|
Posted: Mon Mar 12, 2007 2:25 pm Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
"Peter" <Will_Bounce_So_Use_My_First_Name@Smart-Projects.net> wrote:
| Quote: |
I have a splash screen [...] I would like to make this look
a bit nicer on XP and VISTA systems, with smooth /
transparent
/ blending edges. Now it's rather pixelated and not that
nice depending on the background.
|
Since you can not predict the actual color of the borders, I
would suggest that you remove the borders from your splash
form (which I would suggest in any case). The splash screen
should be just a splash of what's to come and perhaps also
show progress of the application loading.
| Quote: | [...] is it all possible to create the effect I wish from a
bmp for which on colour is made transparent ?
|
Not if you can not predict the color of the on-screen pixel
at a specif location which you can not. You would need to
depend on the user loading (or having set) a theme where the
borders are solid (which they seldom are) and then you'd have
to dynamically create a bitmap and dynamically set it's pixels
to meet your needs based on the current screen composition.
To be clear, you can get the screen image and go from there
but that is definately the wrong approach.
| Quote: | Or is there more to it and will I also need to change the
code that converts this one colour ? Or will a bmp not do
and do I need something else ?
|
A splash screen should not be interactive but rather a visual
cue to the user that your application is loading .... period.
Considering this, it does not need a Caption or any biIcons or
anything else for that matter ... just an image that relates
to the user that you application is loading.
If your splash does more than that then you need to rework
the logic.
~ JD |
|
| Back to top |
|
 |
Peter Guest
|
Posted: Mon Mar 12, 2007 7:30 pm Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
| Quote: | Since you can not predict the actual color of the borders, I
would suggest that you remove the borders from your splash
form (which I would suggest in any case). The splash screen
should be just a splash of what's to come and perhaps also
show progress of the application loading.
|
To be clear, there are no window borders, no caption, no biIcons etc.
It's just a bmp picture and the edges of the picture are made transparent
(by the code I mentioned)
In other words, it's not a square but the splash follows the contours of the
logo in the bmp.
The colour outside the non-square logo is made transparent.
But I thought / hoped that it would be possible maybe to have the edges of
the logo blend with the background somehow ?
So that the edges aren't so pixelated anymore.
I'm thinking of having the bmp re-worked to facilitate that but I'm not sure
if I can create that effect anyway ?
Maybe a bmp with transparent colour is not the right approach ?
But XP and VISTA icons (for instance) can have that effect I believe ? So
I'm hoping I can do this too somehow ?? |
|
| Back to top |
|
 |
JD Guest
|
Posted: Tue Mar 13, 2007 8:10 am Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
"Peter" <Will_Bounce_So_Use_My_First_Name@Smart-Projects.net> wrote:
| Quote: |
[...] But I thought / hoped that it would be possible maybe
to have the edges of the logo blend with the background
somehow ?
|
You could use that approach. Basically, you grab an image of
the area of the screen where your image will go and then blend
the pixles from the 2 images as desired.
| Quote: | [...] Maybe a bmp with transparent colour is not the right
approach ?
|
It's difficult to say because I'm still uncertain of what
exactly you're problem is. Perhaps a Bitmap or 2 posted
to the attachment group would help.
~ JD |
|
| Back to top |
|
 |
Peter Guest
|
Posted: Tue Mar 13, 2007 9:00 pm Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
| Quote: | [...] But I thought / hoped that it would be possible maybe
to have the edges of the logo blend with the background
somehow ?
You could use that approach. Basically, you grab an image of
the area of the screen where your image will go and then blend
the pixles from the 2 images as desired.
|
Yeah but I never know what the background will be.
| Quote: | [...] Maybe a bmp with transparent colour is not the right
approach ?
It's difficult to say because I'm still uncertain of what
exactly you're problem is. Perhaps a Bitmap or 2 posted
to the attachment group would help.
|
Ok, I hope you don't mind a few links instead.
This is what you see when my app starts under XP (a typical desktop
background)
http://www.smart-projects.net/temp/splash_XP_desktop.jpg
This is the same under VISTA:
http://www.smart-projects.net/temp/splash_VISTA_desktop.jpg
An example of a Windows window, where I feel that the edge blends very
nicely with the background, no matter what that background is (example
blends with various colours of the background):
http://www.smart-projects.net/temp/VISTA_window_blending.jpg
My point, can I create such an effect (see last jpg) by having my bmp
reworked ?
Or is there more to it ?
I mean, I can have my bmp reworked, for instance remove the grey contours,
but then the black will be pixelated and not look good on certain desktops /
backgrounds.
However, if I can create sort of a blending effect like you see in the vista
example then that would solve things.
The reason for this question in this NG is to determine whether what I want
is at all possible with a reworked bmp and code that makes one colour of the
bmp transparent ?
I need to know what to ask from a graphical expert before I continue.
Maybe there's much more to it ? |
|
| Back to top |
|
 |
Clayton Arends Guest
|
Posted: Tue Mar 13, 2007 9:30 pm Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
PNG works really well for multiple levels of transparency. If you don't
already have TPNGObject then head to http://pngdelphi.sourceforge.net/ and
take a look at it. I've been using PNG graphics internally for years to
avoid the nasty edge issues that either require you to know the background
color or make your icons with non blending edges.
However, for the matter of using a PNG to define the shape of a window/form
that is a little trickier. You can very easily determine which areas are
completely transparent (much the way you do in your BMP by defining a
certain color to be the "transparent color"). But the pixels that should be
blended with the background will have to know what the other color is in the
background. The reason for this is that the Win32 API only allows for 100%
transparent or 100% opaque pixels in a region.
Define the transparent region of your window to be the 100% transparent
pixels of your PNG. Take a static "screenshot" bitmap of the area that your
form will cover. When you need to draw your splash screen (either by using
a TImage or by responding to WM_PAINT commands or using a TPaintBox) you
will draw the screen bitmap first followed by your PNG. The upside to this
approach is you will have pretty blended edges. The downside is that if any
graphic changes behind your splash screen then your static image will be out
of sync. I have seen programs that detect changes, update their screen
image, and then redraw their form but I haven't researched how something
like that would be possible without annoying flickering.
I also haven't researched much at all about Vista. It might have new APIs
that allow you to have regions that define multiple transparency levels.
- Clayton |
|
| Back to top |
|
 |
JD Guest
|
Posted: Tue Mar 13, 2007 11:07 pm Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
"Peter" <Will_Bounce_So_Use_My_First_Name@Smart-Projects.net> wrote:
| Quote: |
You could use that approach. Basically, you grab an image of
the area of the screen where your image will go and then blend
the pixles from the 2 images as desired.
Yeah but I never know what the background will be.
|
You will once you grab the screen's image.
| Quote: | Ok, I hope you don't mind a few links instead.
|
I am not authorized to view those pages!
~ JD |
|
| Back to top |
|
 |
Peter Guest
|
Posted: Wed Mar 14, 2007 12:30 am Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
| Quote: | I am not authorized to view those pages!
|
posted in the attachments group ! |
|
| Back to top |
|
 |
Michael Kutscher Guest
|
Posted: Wed Mar 14, 2007 3:20 am Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
Hi,
| Quote: | PNG works really well for multiple levels of transparency. If you don't
already have TPNGObject then head to http://pngdelphi.sourceforge.net/ and
take a look at it. I've been using PNG graphics internally for years to
avoid the nasty edge issues that either require you to know the background
color or make your icons with non blending edges.
|
I just stumbled into this and found the Idea interesting, to integrate
PNG into my programs.
Unfortionately, when I try to compile those units, I get an error at
procedure RemoveChunk(Chunk: TChunk); overload;
"Field definition not alloewed after methods or properties".
When I cut away that "overload;" it gets compiled, but system crashes
when I try to install the component.
I'm using C++-Builder 3.0 (yes, I know, its old, but it should work with
it.)
Im not good with PASCAL at all :-(
Do You know, what's wrong or if there is a version anywhere, working
with builder3?
Best regards
Michael Kutscher |
|
| Back to top |
|
 |
Clayton Arends Guest
|
Posted: Wed Mar 14, 2007 3:28 am Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
The release notes in pngimage.pas specify that it should work with Delphi 3
(therefore BCB3). BCB3 is the only version of C++Builder that I do not have
a copy of so I'm afraid I cannot test compile for myself.
| Quote: | procedure RemoveChunk(Chunk: TChunk); overload;
"Field definition not alloewed after methods or properties".
|
The problem most likely is that overload probably didn't exist in Delphi 3.
I am no expert on knowlng what language features were added to Delphi and
when, however. But, looking at the code as a whole I see no reason why
overload should be there in the first place. There is no other
RemoveChunk() method. Removing it should be fine.
| Quote: | but system crashes when I try to install the component.
|
How do you mean crashes? Is there an error message?
- Clayton |
|
| Back to top |
|
 |
Michael Kutscher Guest
|
Posted: Wed Mar 14, 2007 4:20 am Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
Hi,
thanks for the reply.
| Quote: | The problem most likely is that overload probably didn't exist in Delphi 3.
I am no expert on knowlng what language features were added to Delphi and
when, however.
I've also picked an older version of TPNGImage where Builder-3 is |
expilicitly mentioned, but its the same problem.
| Quote: | But, looking at the code as a whole I see no reason why
overload should be there in the first place. There is no other
RemoveChunk() method. Removing it should be fine.
|
I'll try it again. I think I will remove any traces of the tries I made
and set it up again on a "clean" system.
| Quote: | but system crashes when I try to install the component.
How do you mean crashes? Is there an error message?
|
I got an protection-fault when trying to install the component.
Afterwards the PNGButton was present in the component-bar, but when I
tried to use that, I got several protection-faults and at last it was
not possible to close C++-Builder itself. I had to use the reset-button,
to kill it.
Best regards
Michael Kutscher |
|
| Back to top |
|
 |
JD Guest
|
Posted: Wed Mar 14, 2007 7:19 am Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
"Peter" <Will_Bounce_So_Use_My_First_Name@Smart-Projects.net> wrote:
The images are a bit small but looking at the last one's
border, it appears that you're not looking to make the
border transparent but rather semi-transparent. This can be
accomplished as I noted earlier; you grab the portion of the
screen that you need (where the new image is going to go)
and then blend it with your image before you display the
image. For example:
// assumes source image is in a TBitmap named KBBmp
ScrnBmp = new Graphics::TBitmap();
ScrnBmp->PixelFormat = pf24bit;
ScrnBmp->Canvas->Brush->Style = bsClear;
ScrnBmp->Width = KBBmp->Width;
ScrnBmp->Height = KBBmp->Height;
HWND hWnd = ::GetDesktopWindow();
HDC hDC = ::GetWindowDC( hWnd );
::BitBlt( ScrnBmp->Canvas->Handle, 0, 0, ScrnBmp->Width, ScrnBmp->Height, hDC, 0, 0, SRCCOPY );
OutBmp = new Graphics::TBitmap();
OutBmp->PixelFormat = pf24bit;
OutBmp->Canvas->Brush->Style = bsClear;
OutBmp->Width = ScrnBmp->Width;
OutBmp->Height = ScrnBmp->Height;
int r,g,b;
BYTE *Scrn,*Kbrd,*Out;
DWORD SWeight, TWeight = 150;
SWeight = 255 - TWeight;
for( int y = 0; y < KBBmp->Height; ++y )
{
Out = static_cast<BYTE*>( OutBmp->ScanLine[y] );
Scrn = static_cast<BYTE*>( ScrnBmp->ScanLine[y] );
Kbrd = static_cast<BYTE*>( KBBmp->ScanLine[y] );
for( int x = 0; x < KBBmp->Width; ++x )
{
r = x * 3;
g = r + 1;
b = r + 2;
Out[r] = (BYTE)((((DWORD)Kbrd[r] * TWeight) + ((DWORD)Scrn[r] * SWeight)) >> ;
Out[g] = (BYTE)((((DWORD)Kbrd[g] * TWeight) + ((DWORD)Scrn[g] * SWeight)) >> ;
Out[b] = (BYTE)((((DWORD)Kbrd[b] * TWeight) + ((DWORD)Scrn[b] * SWeight)) >> ;
}
}
::BitBlt( hDC, 0, 0, OutBmp->Width, OutBmp->Height, OutBmp->Canvas->Handle, 0, 0, SRCCOPY );
::ReleaseDC( hWnd, hDC );
Note that changing the target weight (TWeight variable) will
change the level of opacity. Valid values are 0 through 255
inclusive with a value of 255 resulting no transparency at all.
The closer you go toward zero, the more of the backgound that
shows through until you hit zero and none of the original can
be seen.
~ JD |
|
| Back to top |
|
 |
Peter Guest
|
Posted: Wed Mar 14, 2007 6:45 pm Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
| Quote: | The images are a bit small but looking at the last one's
border, it appears that you're not looking to make the
border transparent but rather semi-transparent. This can be
accomplished as I noted earlier; you grab the portion of the
screen that you need (where the new image is going to go)
and then blend it with your image before you display the
image. For example:
|
Interesting !
- When there are other apps showing already, so the splash would appear on
top of those, will ScrnBmp get that data as well ? Or will this code only
grab the desktop image (possibly underneath other apps) ?
- The splash stays up until my app has loaded in the background.
In other words, at some point my own app appears behind the splash before
the splash disappears.
So I gather this will "screw" up the blending then ? |
|
| Back to top |
|
 |
JD Guest
|
Posted: Wed Mar 14, 2007 8:07 pm Post subject: Re: smooth / transparent / blending edges splash screen - XP |
|
|
"Peter" <Will_Bounce_So_Use_My_First_Name@Smart-Projects.net> wrote:
| Quote: |
When there are other apps showing already, so the splash
would appear on top of those, will ScrnBmp get that data as
well ?
|
Yes.
| Quote: | Or will this code only grab the desktop image (possibly
underneath other apps) ?
|
When an application is visible, it's image is part of the
DeskTop.
| Quote: | at some point my own app appears behind the splash before
the splash disappears. So I gather this will "screw" up the
blending then ?
|
That's another reason why I suggested using a TForm.
If all you're doing is painting the image to the screen, then
your application will (or should) appear over the splash image
and then you're done (except for destroying objects).
If you want your image to appear above the application and then
disappear, you'll need to draw the image again in the form's
OnShow event.
~ JD |
|
| Back to top |
|
 |
|
|
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
|
|