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
Solved

Canvas to Tgraphic

Posted on 1997-11-02
2
849 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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