?
Solved

Canvas to Tgraphic

Posted on 1997-11-02
2
Medium Priority
?
869 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
[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
2 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 300 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

764 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