Solved

Print TForm.Canvas as Bitmap

Posted on 2000-02-15
5
353 Views
Last Modified: 2013-12-03
I am developing a charting application.  I use the Canvas of TForm as my drawing area.  Is there a way for me to save my drawing as a bitmap file?

My current solution is to use BitBlt, but the problem with this is that when other windows popup over the Form which is being saved; they will also be included in the bitmap.  Furthermore, with BitBlt I cannot save the canvas of a Form when the form is minimized. How do I work on this?
0
Comment
Question by:newind
5 Comments
 
LVL 2

Accepted Solution

by:
hubdog earned 150 total points
ID: 2521916
tform.GetFormImage method can return a tbitmap

good luck
hubdog
            
0
 
LVL 2

Expert Comment

by:hubdog
ID: 2521919
tform.GetFormImage method can return a tbitmap

good luck
hubdog
            
0
 
LVL 2

Expert Comment

by:aubs
ID: 2521927
You should try using a bitmap created in memory rather than the form's canvas to draw on. Saving the bitmap is far easier too.

These needs tidying up, but should give you a better idea...

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Bitmap: TBitmap;
implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
      bitmap:= TBitmap.Create;
  bitmap.Width:= Clientwidth;
  bitmap.height:= clientheight;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  bitmap.Free;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  bitmap.Canvas.LineTo(X,Y);
  canvas.Draw(0,0,bitmap);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  bitmap.SaveToFile('c:\temp\test.bmp');
end;

end.



Aubs
0
 
LVL 1

Expert Comment

by:AttarSoftware
ID: 2522010
Does :
 
  myBmp := tBitmap.Create ;
  myBmp.Width := Form1.Width ;
  myBmp.Height := Form1.Height ;
  Form1.PaintTo( myBmp.Canvas.Handle, 0, 0 ) ;
 
work?

Good luck,

Tim.
0
 

Author Comment

by:newind
ID: 2525426
Well I say it's a great function.  It did solve my problem.

Thanks a lot hubdog!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 64
Intraweb download file link ? 1 107
Strange behavior when a form is closed 6 51
tidtcpserver connection lost handle 2 70
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now