| View previous topic :: View next topic |
| Author |
Message |
wzsun Member
Joined: 31 Jul 2003 Posts: 6
|
Posted: 31/07/03 14:29 Post subject: Drawing on a PicShow canvas |
|
|
Hi,
Is there a way to create a canvas handle of PicShow so that I can draw anything on it? I'm trying to simulate the Pen tool from Powerpoint so that in my PicShow project... there's a pen tool where I can draw on the canvas.
Any help on how to create the canvas and sample code would be appreciated.
Rgds
WZSun |
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 235
|
Posted: 31/07/03 21:25 Post subject: |
|
|
You can draw on the bounding rectangle of a transition inside the handler of following events:
OnStart
OnBeforeNewFrame
OnAfterNewFrame
For your case, I think you should draw on the Screen bitmap parameter of the OnAfterNewFrame event.
For drawing outside of the bounding rectangle of a transition there is solution, however you can use BgPicture property to draw on it.
Kambiz |
|
| Back to top |
|
 |
wzsun Member
Joined: 31 Jul 2003 Posts: 6
|
Posted: 02/08/03 03:31 Post subject: How do I use BGPicture |
|
|
Hi Kambiz,
Thanks for the info. I tried using BGPicture. but couldn't get anything. Sometimes I get the 'Canvas does not allow drawing..'
in my code I tried doingsomething like this:
Canvas := TCanvas.Create;
Canvas.Handle := PicShow.BGPicture.Bitmap.Handle;
..
..
Canvas.LineTo(Pos.X, Pos.Y);
Any help is appreciated.. |
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 235
|
Posted: 02/08/03 03:38 Post subject: |
|
|
First you have to set the size of BgPicture.Bitmap, and then you can draw on BgPicture.Bitmap.Canvas.
Kambiz |
|
| Back to top |
|
 |
wzsun Member
Joined: 31 Jul 2003 Posts: 6
|
Posted: 02/08/03 10:06 Post subject: Tried it.. but nothing appears |
|
|
Hi Kambiz,
Below is a sample code that I did.. somehow there's nothing at all.
To check whether the 'LoadedImage' is set wrongly, I even tried changing the image file to:
PicShow.BgPicture.Bitmap.LoadFromFile('c:\temp\test.bmp');
but still nothing happens. I managed to draw on a TImage.. but somehow I think there's something missing that I have not done.. it's just that I'm not sure where/what it is..
Any help is appreciated....
procedure TMainForm.PenButtonClick(Sender: TObject);
begin
Dragging := False;
PicShow.BgPicture.Bitmap.LoadFromFile(LoadedImage);
Canvas := TCanvas.Create;
Canvas.Handle := PicShow.BgPicture.Bitmap.Handle;
Canvas.Pen.Color := clRed;
Canvas.Brush.Color := clBlue;
Canvas.Brush.Style := bsSolid;
Canvas.Pen.Width := 10;
end;
procedure TMainForm.PicShowMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
if Tool = 'Pen' then
begin
if ssLeft in Shift then
begin
if Dragging then
begin
Canvas.LineTo(Pos.X, Pos.Y);
Pos := Point(X, Y);
end;
end;
end;
end;
procedure TMainForm.PicShowMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Tool = 'Pen' then
begin
PicShow.Cursor := crDefault;
Dragging := False;
end;
end;
procedure TMainForm.PicShowMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Tool = 'Pointer' then
begin
if PicShow.Busy then exit;
PicShow.Enabled := False; // To prevent reentrance
try
if ssLeft in Shift then
ShowNextImage;
finally
PicShow.Enabled := True;
end;
end;
// Pen
if Tool = 'Pen' then
begin
if ssLeft in Shift then
begin
Dragging := True;
Pos := Point(X, Y);
Canvas.MoveTo(Pos.X, Pos.Y);
end;
end;
end; |
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 235
|
Posted: 02/08/03 13:50 Post subject: Re: Tried it.. but nothing appears |
|
|
| wzsun wrote: | Hi Kambiz,
procedure TMainForm.PenButtonClick(Sender: TObject);
begin
Dragging := False;
PicShow.BgPicture.Bitmap.LoadFromFile(LoadedImage);
Canvas := TCanvas.Create;
Canvas.Handle := PicShow.BgPicture.Bitmap.Handle;
Canvas.Pen.Color := clRed;
Canvas.Brush.Color := clBlue;
Canvas.Brush.Style := bsSolid;
Canvas.Pen.Width := 10;
end;
|
I didn't read your entire code because in the above code I saw some serious mistakes:
1. The bitmap handle is not a canvas handle. Instead of assigning PicShow.BgPicture.Bitmap.Handle to the Canvas.Handle, you should assign PicShow.BgPicture.Bitmap.Canvas.Handle to it.
2. You might not create a new canvas, otherwise changes on the canvas will not be reported to the PicShow. Instead of creating a new canvas, you have use PicShow.BgPicture.Bitmap.Canvas. In this case, you do not need to assign any handle to the canvas.handle.
3. I hope you have set the PicShow.BgMode proprty to a right value.
4. The bgPicture is the background image. So, if the image loaded in the Picture property is visible, it will covers the background image.
Kambiz |
|
| Back to top |
|
 |
|