Drawing on a PicShow canvas

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

Drawing on a PicShow canvas

Postby wzsun » July 31st, 2003, 2:29 pm

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
wzsun
Active Member
Active Member
 
Posts: 6
Joined: July 31st, 2003, 2:26 pm

Postby Kambiz » July 31st, 2003, 9:25 pm

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
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

How do I use BGPicture

Postby wzsun » August 2nd, 2003, 3:31 am

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..
wzsun
Active Member
Active Member
 
Posts: 6
Joined: July 31st, 2003, 2:26 pm

Postby Kambiz » August 2nd, 2003, 3:38 am

First you have to set the size of BgPicture.Bitmap, and then you can draw on BgPicture.Bitmap.Canvas.

Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Tried it.. but nothing appears

Postby wzsun » August 2nd, 2003, 10:06 am

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;
wzsun
Active Member
Active Member
 
Posts: 6
Joined: July 31st, 2003, 2:26 pm

Re: Tried it.. but nothing appears

Postby Kambiz » August 2nd, 2003, 1:50 pm

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
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 2 guests

cron