Discussion:
How to clear transparent Canvas?
(too old to reply)
aaaa
2011-12-26 16:44:28 UTC
Permalink
Hi,
I have drawn something on a transparent Canvas.
Now I want to erase it. I don't want to paint a white rectangle- I want to
paint a "transparent" rectangle on Canvas to erase my stuff.

How can I do this?

Setting Brush.Style to bsClear doesn't do the trick- it paints only
rectangle's frame (no background) and not a rectangle with "tranparent color
filled" background.

Best regards,
A
Jamie
2011-12-26 18:47:08 UTC
Permalink
Post by aaaa
Hi,
I have drawn something on a transparent Canvas.
Now I want to erase it. I don't want to paint a white rectangle- I want
to paint a "transparent" rectangle on Canvas to erase my stuff.
How can I do this?
Setting Brush.Style to bsClear doesn't do the trick- it paints only
rectangle's frame (no background) and not a rectangle with "tranparent
color filled" background.
Best regards,
A
You obviously assume what ever is on the background behind your
canvas/form is automatically recoverable?

It is a canvas for which you are covering up something else with?
Since you are covering forms, how do you expect it to restore what was
there?

With initial form display you most likely have left over image junk
from the form behind you. This is junk and not to be relied on.

If you are using a canvas with a clear brush, you can not simply pop
back what was there however, you can shut off the form that contains the
canvas to force the forms/background to refresh and then reinstate the
transparent canvas form.

Other things you can do is grab a snap shot of the canvas on first
initial start before you draw on it, then use that Tbitmap to later
paint over it to restore the original baggage image that was there
before that.

Now, Are you sure you're talking about a transparent form?

Jamie
aaaa
2011-12-26 22:31:56 UTC
Permalink
I know that and I wonder how to do this most efficiently.

When I do:
MyComponent.Visible := False;
MyComponent.Visible := True;
everything that is behind my component gets repainted and then my
component's Paint() method gets called and everything looks great.
And my component is transparent because I can see the labels and other
controls placed behind it.

The thing is- what exactly is this "Visible" doing...?

The idea of saving the snapshop as TBitmap is nice- I think it should make
"clearing" faster. After all nothing will change behind my component as long
as it is Focused and when it looses Focus I can resave the snapshop.

How to get the snapshop in the best way? Should I iterate all controls of my
component's parent and invoke their WM_PAINT somehow onto my snapshot's
TBitmap? Or is there any easier way?

Best regards,
A
Jamie
2011-12-27 02:27:52 UTC
Permalink
This post might be inappropriate. Click to display it.
88888 Dihedral
2011-12-27 20:20:29 UTC
Permalink
Jamie於 2011年12月27日星期二UTC+8上午10時27分52秒寫道:
Post by Jamie
Post by aaaa
I know that and I wonder how to do this most efficiently.
MyComponent.Visible := False;
MyComponent.Visible := True;
everything that is behind my component gets repainted and then my
component's Paint() method gets called and everything looks great.
And my component is transparent because I can see the labels and other
controls placed behind it.
The thing is- what exactly is this "Visible" doing...?
The idea of saving the snapshop as TBitmap is nice- I think it should
make "clearing" faster. After all nothing will change behind my
component as long as it is Focused and when it looses Focus I can resave
the snapshop.
How to get the snapshop in the best way? Should I iterate all controls
of my component's parent and invoke their WM_PAINT somehow onto my
snapshot's TBitmap? Or is there any easier way?
Best regards,
A
You could wedge into the Paint Method of each control but wouldn't
be easier to simply create a control of your own that will do this for you?
You simply start with an existing control and build on that.
Its not clear exactly what you're trying to do yet..
P.S.
If you have not made a control yet, maybe this is a good time to
learn.
Jamie
In Delphie the object in the display image of a Window is different
from the image.scanline[j] as far as I know.

The container and the content are separate objects to be programmed
by the programmer.
battles
2011-12-28 00:59:22 UTC
Permalink
Post by aaaa
Hi,
I have drawn something on a transparent Canvas.
Now I want to erase it. I don't want to paint a white rectangle- I want to
paint a "transparent" rectangle on Canvas to erase my stuff.
How can I do this?
Setting Brush.Style to bsClear doesn't do the trick- it paints only
rectangle's frame (no background) and not a rectangle with "tranparent color
filled" background.
Best regards,
Would something like

Image1.Picture := nil;

work here? This is how you clear an image.

Loading...