Solved

Canvas to Tgraphic

Posted on 1997-11-02
2
834 Views
Last Modified: 2012-06-21
To place a Graphic onto a Canvas you simply call canvas.draw(x,y,graphic). But how do I go the other
way i.e. I have drawn some stuff on the canvas and want
to make a Bitmap (Graphic) out of it?
I envision something like Copyrect where you would pass it a
rectangle and the Bitmap would be made from that.
0
Comment
Question by:AndrewEarl
2 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1349377
Hi

The following code draws some lines on the form's canvas, copies that section of the form's canvas to a bitmap and saves the bitmap to disk.

procedure TForm1.Button1Click(Sender: TObject);
var
    Bmp: TBitmap;
begin
    // Draw on form's canvas.
    Canvas.MoveTo(5, 5);
    Canvas.LineTo(90, 80);
    Canvas.Pen.Color := clRed;
    Canvas.LineTo(40, 90);

    // Create bitmap.
    Bmp := TBitmap.Create;
    Bmp.Height := 100;
    Bmp.Width := 100;

    // Copy form's canvas onto the bitmap.
    Bmp.Canvas.CopyRect(Rect(0, 0, 100, 100), Self.Canvas, Rect(0, 0, 100, 100));

    // Save bitmap, and free it.
    Bmp.SaveToFile('C:\Temp.bmp');
    Bmp.Free;
end;

Hope this helps you.
JB
0
 

Author Comment

by:AndrewEarl
ID: 1349378
Thank you. Works well.

I'm actually using Tpicture, but I get the idea.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

11 Experts available now in Live!

Get 1:1 Help Now