Solved

Print TForm.Canvas as Bitmap

Posted on 2000-02-15
5
361 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Print Graphic and Text to Epson TM-T88v 12 460
control image tags in a string ? 12 153
Broadcast a message using ICS 2 20
How to change fonts in windows live mail 3 17
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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