Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Print TForm.Canvas as Bitmap

Posted on 2000-02-15
5
Medium Priority
?
375 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Accepted Solution

by:
hubdog earned 600 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

705 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