Solved

Metafile.Canvas?

Posted on 1998-01-14
1
176 Views
Last Modified: 2010-04-04
Obviously the TMetafile doesn't have a Canvas property. How can I use functions like LineTo() and properties like the Pen, if I later want to copy the image to the Clipboard as a TMetafile?
0
Comment
Question by:friberg
[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
1 Comment
 
LVL 5

Accepted Solution

by:
ronit051397 earned 200 total points
ID: 1356558
This is from Lloyd's help file:

Q:  How can I create a windows meta-file from ellipse(), textOut(), etc. commands?

A:         Here's the latest version of my (Neil Rubenking) metafile-creation example. I've marked the area where you insert your own drawing code. Note that not *every* GDI function can be used in a metafile DC. I've seen a list of those that cannot; alas, it apparently wasn't in the Windows API Help for the metafile functions.

PS - if you're the puzzling type, try to puzzle out just what this program draws before you run it. Or at least, figure what the PolyLine method call draws...


CONST W = 1000; H = 500; R2 = 353;

procedure TForm1.Button1Click(Sender: TObject);

VAR CDC : hDC;

  procedure spiral(CV: TCanvas; Colr: TColor; AngInc: Double;
    RInc: Integer; Sgn1, Sgn2: Integer);
  VAR Theta: Double;
  begin
    Sgn1 := Sgn1 DIV Abs(Sgn1);
    Sgn2 := Sgn2 DIV Abs(Sgn2);
    CV.pen.Color := Colr;
    Theta := 0;
    CV.MoveTo(H,H);
    WHILE Theta < pred(H DIV RInc) DO
      BEGIN
        Theta := Theta + AngInc;
        CV.LineTo(H+Sgn1*Round(RInc*Theta*Cos(Sgn2*Theta)),
                  H+Sgn1*Round(RInc*Theta*Sin(Sgn2*Theta)));
      END;
  end;

begin
  DeleteFile('EXAMPLE.WMF');
  WITH TBitmap.Create DO
    try
      CDC := CreateMetafile(NIL);
      Canvas.Handle := CDC;
      SetMapMode(Canvas.Handle, MM_ANISOTROPIC);
      SetWindowExt(Canvas.Handle, W, W);
      WITH Canvas DO
        BEGIN
          {==== replace with your own image-creation code ===}
          Brush.Color := clWhite;
          pen.Width := 10;
          pen.Style := psInsideFrame;
          pen.Color := clBlack;
          Ellipse(0,0,W,W);
          Spiral(Canvas, clRed, pi/4, 18, 1, 1);
          Spiral(Canvas, clBlue, pi/4, 18, -1, 1);

          Pen.Color := clBlack;
          PolyLine([Point(H,0), Point(H,H), Point(H-R2, H+R2),
            Point(H,H), Point(H,W), Point(H,H),
            Point(H+R2,H+R2)]);
          {====== end image-creation code =====}
        END;
      WITH TMetafile.Create DO
        try
          Handle := CloseMetafile(CDC);
          Inch   := W;
          Height := 128;
          Width  := 128;
          SaveToFile('EXAMPLE.WMF');
        finally
          Free;
        end;
    finally

      Free;
    end;
end;

{ This code came from Lloyd's help file! }
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

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…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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