 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
John Guest
|
Posted: Thu May 17, 2007 5:11 am Post subject: Moving picture over the PC desktop? How can I do that? |
|
|
Hi all, I'm using Builder 4.0, and What I want to do is to take
a picture of any object, for example an airplane, or a ball, or
a car, and to make it move left and right on my desktop, how
can I do that?
I think that what I need is a transparent form, and on this form
I should put a TImage, and set 'Transparent=true' in the image
properties, and then to load my picture, which will include the
object in the middle, and a transparent background around it.
But how can I do that? How can I create a transparent form?
A piece of an example code can be nice.
Thanks! |
|
| Back to top |
|
 |
JD Guest
|
Posted: Fri May 18, 2007 8:11 am Post subject: Re: Moving picture over the PC desktop? How can I do that? |
|
|
"John" <MyMail (AT) None (DOT) com> wrote:
This question would have been best asked in the graphics group.
| Quote: | [...] What I want to do is to take a picture of any object,
[...] and to make it move left and right on my desktop,
|
You need to first save the portion of the desktop where the
image will be painted, paint the image and then restore that
portion of the desktop (in a loop).
Exactly how you would do this depends on your requirements.
For example, it's safe to assume that you don't want a square
ball but since anything other than rectangular screen I/O
will be way to slow, your loop will also need to blend the
saved portion of the desktop with the image into a 3rd Bitmap
that gets painted to the screen. For example (assumes pf24bit):
// Original Bitmap allocation not shown
OrgBmp->LoadFromFile( "SomeFileName" );
DskBmp = new Graphics::TBitmap();
DskBmp->PixelFormat = pf24bit;
DskBmp->Canvas->Brush->Style = bsClear; // reported to speed up operations
DskBmp->Width = OrgBmp->Width;
DskBmp->Height = OrgBmp->Height;
HWND hWnd = ::GetDesktopWindow();
HDC hDC = ::GetWindowDC( hWnd );
::BitBlt( DskBmp->Canvas->Handle, 0, 0, DskBmp->Width, DskBmp->Height, hDC, 0, 0, SRCCOPY );
OutBmp = new Graphics::TBitmap();
OutBmp->PixelFormat = pf24bit;
OutBmp->Canvas->Brush->Style = bsClear;
OutBmp->Width = OrgBmp->Width;
OutBmp->Height = OrgBmp->Height;
BYTE *Org, *Dsk, *Out;
int C = ColorToRGB( OrgBmp->Pixels[0][OrgBmp->Height - 1] );
int R = ( GetRValue(C) << 8 );
int G = ( GetGValue(C) << 8 );
int B = ( GetBValue(C) << 8 );
for( int y = 0; y < OrgBmp->Height; ++y )
{
Org = static_cast<BYTE*>( OrgBmp->ScanLine[y] );
Dsk = static_cast<BYTE*>( DskBmp->ScanLine[y] );
Out = static_cast<BYTE*>( OutBmp->ScanLine[y] );
for( int x = 0; x < OrgBmp->Width; ++x )
{
if( Org[x * 3 + 0] == R && Org[x * 3 + 1] == G && Org[x * 3 + 2] == B )
{
Out[x * 3 + 0] = Dsk[x * 3 + 0];
Out[x * 3 + 1] = Dsk[x * 3 + 1];
Out[x * 3 + 2] = Dsk[x * 3 + 2];
}
else
{
Out[x * 3 + 0] = Org[x * 3 + 0];
Out[x * 3 + 1] = Org[x * 3 + 1];
Out[x * 3 + 2] = Org[x * 3 + 2];
}
}
}
::BitBlt( hDC, 0, 0, OutBmp->Width, OutBmp->Height, OutBmp->Canvas->Handle, 0, 0, SRCCOPY );
::ReleaseDC( hWnd, hDC );
The above assumes that the lower left pixel in the original
image is the transparent color and it compares that color to
each pixel in the image to determine if the Out pixel should
come from the image or the desktop. This method can be greatly
improved if put into a loop if you scan the original once and
create a 2D array of bools instead. That way you don't have to
compare each pixel over and over.
You might also consider just copying the image to Out and then
filling in the transparent parts from the desktop using the 2D
array of bools.
Also note that if you want to move it about the screen, you
need to change the BitBlt parameters.
| Quote: | I think that what I need is a transparent form,
|
That might work if the form is borderless and captionless
and you certainly need some way to end the application
(unless the animation is part of a larger project).
| Quote: | put a TImage, and set 'Transparent=true' in the image
properties, and then to load my picture, which will include
the object in the middle, and a transparent background
around it.
|
You'd also have the form's TransparentColor and
TransparentColorValue properties (which you may not
have in BCB4).
However, I would think that an application that does this
type of thing would not be on the taskbar and would just time
out and kill itself or maybe it would minimize to the tray.
~ JD |
|
| Back to top |
|
 |
John Guest
|
Posted: Fri May 18, 2007 9:04 pm Post subject: Re: Moving picture over the PC desktop? How can I do that? |
|
|
Thanks, I will try it... is it the shortest way to do that? |
|
| Back to top |
|
 |
JD Guest
|
Posted: Tue May 22, 2007 5:26 am Post subject: Re: Moving picture over the PC desktop? How can I do that? |
|
|
"John" <MyMail (AT) None (DOT) com> wrote:
| Quote: |
[...] is it the shortest way to do that?
|
In terms of writing code? Not if you can get a transparent
TImage working with a transparent TForm but it certainly
is the fastest code that you can write without going to
assembler.
~ 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
|
|