Solved

Print TForm.Canvas as Bitmap

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

9 Experts available now in Live!

Get 1:1 Help Now