Solved

Metafile.Canvas?

Posted on 1998-01-14
1
169 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
1 Comment
 
LVL 5

Accepted Solution

by:
ronit051397 earned 200 total points
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

9 Experts available now in Live!

Get 1:1 Help Now