Board index » delphi » Trying to mask a Flash file

Trying to mask a Flash file


2007-08-01 04:03:28 AM
delphi28
I'm trying to put the Flash.ocx ActiveX control on a form, and then have a
graphic with transparent area(s) appear over top of the Flash playback to
create a "mask" effect. I was originally trying it in Delphi 7 Pro, since
that was what was open, but I am always getting the Flash file appearing over
top of the image.
I searched for a "transparent panel" component (and found one), thinking
that I needed my image to be on something that is descended from TWinControl.
But that didn't help, either.
When I ran my test program, I see a glimpse of my graphic image before it
gets covered by the Flash playback.
Can anyone suggest an approach that might work?
Thanks.
 
 

Re:Trying to mask a Flash file

Warrick Wilson writes:
Quote
I'm trying to put the Flash.ocx ActiveX control on a form, and then
have a graphic with transparent area(s) appear over top of the Flash
playback to create a "mask" effect. I was originally trying it in
Delphi 7 Pro, since that was what was open, but I am always getting
the Flash file appearing over top of the image.

I searched for a "transparent panel" component (and found one),
thinking that I needed my image to be on something that is descended
from TWinControl. But that didn't help, either.

When I ran my test program, I see a glimpse of my graphic image
before it gets covered by the Flash playback.

Can anyone suggest an approach that might work?

Thanks.
The Flash.OCX will not display a transparent SWF in Delphi.
There is, however, a third-party player that does but I don't
remember the name of it.
--
 

Re:Trying to mask a Flash file

"Eddie Shipman" <XXXX@XXXXX.COM>writes
Quote
Warrick Wilson writes:

The Flash.OCX will not display a transparent SWF in Delphi.
There is, however, a third-party player that does but I don't
remember the name of it.
Sorry - I knew this was going to be awkward to explain, even if English is
my first language :).
I'm not trying to play a transparent SWF. What I want to do is try and
create a "keyhole" effect, where the Flash is playing BEHIND an image that
is all black except for a keyhole shape that is in a "transparent color". So
created an image with a transparentcolor area (RGB(255,0,255)) and tried to
assign that to a panel that was somehow "in front" of the panel with the
Flash control on it. The (desired) end result would be that the Flash file
content appears in the transparentcolor area.
Maybe it is not going to work with this approach.
I was considering trying 2 forms - one with the Flash control, one with an
image and transparency set. I haven't gotten there yet - got dragged onto
some real work.
I'm really sort of floundering in what's possible here - I am out of my
comfort/complacency zone with this, though I did something similar (and
easily) with video files using Datastead's TVideoGrabber component. There's
a set of routines in that for exactly this type of feature.
Thanks.
 

Re:Trying to mask a Flash file

Warrick Wilson writes:
Quote
"Eddie Shipman" <XXXX@XXXXX.COM>wrote in
message news:XXXX@XXXXX.COM...
>Warrick Wilson writes:
>
>The Flash.OCX will not display a transparent SWF in Delphi.
>There is, however, a third-party player that does but I don't
>remember the name of it.

Sorry - I knew this was going to be awkward to explain, even if
English is my first language :).

I'm not trying to play a transparent SWF. What I want to do is try
and create a "keyhole" effect, where the Flash is playing BEHIND an
image that is all black except for a keyhole shape that is in a
"transparent color". So created an image with a transparentcolor area
(RGB(255,0,255)) and tried to assign that to a panel that was somehow
"in front" of the panel with the Flash control on it. The (desired)
end result would be that the Flash file content appears in the
transparentcolor area.

Maybe it is not going to work with this approach.

I was considering trying 2 forms - one with the Flash control, one
with an image and transparency set. I haven't gotten there yet - got
dragged onto some real work.

I'm really sort of floundering in what's possible here - I am out of
my comfort/complacency zone with this, though I did something similar
(and easily) with video files using Datastead's TVideoGrabber
component. There's a set of routines in that for exactly this type of
feature.

Thanks.
OK, I see now.
Remember that the transparent color in TImage is set from the
lower-left pixel.
Make sure the lower-left pixel in your image matches the transparent
color you set for your keyhole and see if that helps.
--
 

Re:Trying to mask a Flash file

"Eddie Shipman" <XXXX@XXXXX.COM>writes
Quote

OK, I see now.
Remember that the transparent color in TImage is set from the
lower-left pixel.

Make sure the lower-left pixel in your image matches the transparent
color you set for your keyhole and see if that helps.
It's not the transparent color. I think it is got something to do with the
z-ordering of the components. I tried to just get the image to display in
front of the Flash playback, so that I knew I could at least get the image
in front (forget transparency, just try for the positioning I would need,
essentially), and that didn't work either. I tried playing with the wmode
parameter for the Flash control and that didn't help either.
So my approach is flawed, at least in terms of the "image over Flash control
on one form". So maybe two forms, with one always in front of the other...
That's next on my attempt list.
 

Re:Trying to mask a Flash file

Warrick Wilson writes:
Quote
I'm trying to put the Flash.ocx ActiveX control on a form, and then
have a graphic with transparent area(s) appear over top of the Flash
playback to create a "mask" effect. I was originally trying it in
Delphi 7 Pro, since that was what was open, but I am always getting
the Flash file appearing over top of the image.

I searched for a "transparent panel" component (and found one),
thinking that I needed my image to be on something that is descended
from TWinControl. But that didn't help, either.

When I ran my test program, I see a glimpse of my graphic image
before it gets covered by the Flash playback.

Can anyone suggest an approach that might work?
You cannot put a TGraphicControl on top of a TWincontrol (and an
activeX controls is a TWincontrol descendent) with the same parent. And
since an ActiveX control does not know how to spell TGraphicControl,
much less how to paint one, it is also no use to parent the image to
the activeX control. The only way I see is to obtain a device context
handle for the ActiveX control and directly paint on that device
context. See TControlcanvas, it may work to create one bound to the
ActiveX control and paint on it.
--
Peter Below (TeamB)
Don't be a vampire (slash7.com/pages/vampires),
use the newsgroup archives :
www.tamaracka.com/search.htm
groups.google.com
 

Re:Trying to mask a Flash file

"Peter Below (TeamB)" <none>writes
Quote

You cannot put a TGraphicControl on top of a TWincontrol (and an
activeX controls is a TWincontrol descendent) with the same parent. And
since an ActiveX control does not know how to spell TGraphicControl,
much less how to paint one, it is also no use to parent the image to
the activeX control. The only way I see is to obtain a device context
handle for the ActiveX control and directly paint on that device
context. See TControlcanvas, it may work to create one bound to the
ActiveX control and paint on it.
Thanks for chiming in, Peter. I spent some time with Google looking for
"TControlCanvas" (new item for me), and found some partial matches, but
nothing that really helped. I played around with my example and tried a few
things, but I have not achieved any success. I did, at one point, manage to
get my image to obscure my Flash file totally, but there was not
transparency, and I am not convinced that my Flash file was in fact playing.
Based on your hint, and what I found on the web, I was trying the following:
I added a private FCanvas and a WMPaint handler, like here:
TForm1 = class(TForm)
ShockwaveFlash1: TShockwaveFlash;
Panel1: TPanel;
Image1: TImage;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
FCanvas: TControlCanvas;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
public
{ Public declarations }
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// Try a TControlCanvas
FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := ShockwaveFlash1;
// Set the image transparency values
Image1.Picture.Bitmap.Transparent := True;
Image1.Picture.Bitmap.TransparentColor := RGB(255,0,255);
Image1.Picture.Bitmap.TransparentMode := tmAuto;
// Show the image
FCanvas.StretchDraw(FCanvas.ClipRect, Image1.Picture.Bitmap);
end;
Then I added this (plus a whack of variations) as a WMPaint handler:
procedure TForm1.WMPaint(var Message: TWMPaint);
var
dc: HDC;
begin
dc := GetDC(ShockwaveFlash1.Handle); // a DC for the ActiveX control,
which is housed on a TPanel called Panel1 to set a size
//FCanvas.StretchDraw(FCanvas.ClipRect, Image1.Picture.Bitmap);
//FCanvas.Draw(0, 0, Image1.Picture.Bitmap);
// Playing with the last value (SRCCOPY) for different values per the
online help hasn't made a difference either
StretchBlt(dc, 0, 0, Panel1.Width, Panel1.Height, Image1.Canvas.Handle, 0,
0, Image1.Width, Image1.Height, SRCCOPY);
inherited; // I thought I needed this to let the ActiveX control do its
thing, too .. without it I didn't get any updates from the flash component.
end;
With this as the basic part of my code, I see a brief instance of my image,
and then the Flash plays in the spot. And the image seems the wrong size,
too. I am probably diving too deep on my initial foray into this sort of
stuff, but this is the task I am trying to accomplish.
Any further suggestions would be greatly appreciated...
 

Re:Trying to mask a Flash file

Warrick Wilson writes:
Quote
Any further suggestions would be greatly appreciated...
You need to trap the WM_PAINT messages *to the shockwave control*, not
those on the form level. But even that may not work, it all depends on
how the shockwave player renders its content. What you need to succeed
is a way to inject your drawing code after the player has finished
drawing each frame. And even then the result may flicker horribly. All
in all this sounds like Mission Impossible if the control does not
offer an event that fires after each frame, or can be induced to render
to a bitmap canvas instead of to a control directly.
--
Peter Below (TeamB)
Don't be a vampire (slash7.com/pages/vampires),
use the newsgroup archives :
www.tamaracka.com/search.htm
groups.google.com
 

Re:Trying to mask a Flash file

"Peter Below (TeamB)" <none>writes
Quote
Warrick Wilson writes:

>Any further suggestions would be greatly appreciated...

You need to trap the WM_PAINT messages *to the shockwave control*, not
those on the form level. But even that may not work, it all depends on
how the shockwave player renders its content. What you need to succeed
is a way to inject your drawing code after the player has finished
drawing each frame. And even then the result may flicker horribly. All
in all this sounds like Mission Impossible if the control does not
offer an event that fires after each frame, or can be induced to render
to a bitmap canvas instead of to a control directly.
I wasn't able to find an event that fired after each frame, at least when
using the Adobe Shockwave Flash OCX imported into Delphi.
What I tried that DID work was to put a second form, set to transparent,
with a bitmap that had transparent portions (done with TransparentColor,
etc.) over top of my form playing the Flash ActiveX control. That seems to
work well, at least with the Flash.
I then just turned that second form into a standalone executable that puts a
borderless form in "StayOnTop" mode on the screen, and uses the same
transparent image trick. That works well, too. Until I tried it over a
Quicktime file. Didn't look so good - lots of flicker, etc. But that is a
different topic.
The interesting thing, to me, was that the borderless form allowed clicks to
"go through" to the applications beneath the form. I didn't make any attempt
to intercept them in that program, but it is sort of a weird experience to
work with an application that is beneath what I know is a second running
application. At least, it seems weird to me.
Warrick
 

Re:Trying to mask a Flash file

Warrick Wilson writes:
Quote
The interesting thing, to me, was that the borderless form allowed
clicks to "go through" to the applications beneath the form. I didn't
make any attempt to intercept them in that program, but it is sort of
a weird experience to work with an application that is beneath what I
know is a second running application. At least, it seems weird to me.
That is how Windows handles transparency on the form level, the
transparent parts are taken to be part of the windows underneath when
it comes to mouse processing. The VCL does nothing special here.
--
Peter Below (TeamB)
Don't be a vampire (slash7.com/pages/vampires),
use the newsgroup archives :
www.tamaracka.com/search.htm
groups.google.com
 

Re:Trying to mask a Flash file

"Peter Below (TeamB)" <none>writes
Quote
Warrick Wilson writes:

That is how Windows handles transparency on the form level, the
transparent parts are taken to be part of the windows underneath when
it comes to mouse processing. The VCL does nothing special here.
It's amazing the stuff you find accidentally. it is given me some ideas on
playing with that functionality - both to stop it passing the interactions,
and with taking advantage of it.
On a tangential note to my original issue: I tried the same effect over a
Quicktime file playing in a form. Looked horrible, until I set the Quicktime
player to use "GDI (Safe Mode)" rather than DirectDraw. Then it works the
same as the Flash with respect to the masking. I am not unsurprised by this.
It just makes my intended ultimate goal a little more complicated...