TMetafile and TMetafileCanvas sizing

TMetafile and TMetafileCanvas sizing

Post by J.A. Bijsterbosc » Mon, 24 Aug 1998 04:00:00



Hello All,

Looking at the example for TMetafileCanvas in BCB1's online help and since
I don't have a drawing program that can create *.emf files I wanted to make
a simple editor to draw such files from scratch. However I stumbled on a
sizing problem that I seem not able to solve. According to the example I
have the following in a OnMouseUp event:

void __fastcall TMainForm::PaintBoxMouseUp(TObject *Sender, TMouseButton
Button,         TShiftState Shift, int X, int Y)
{
  if( Button == mbLeft ) {
    mouseDown = false;
    switch( ActiveButton ) {
    case 1: {
        PaintBox->Canvas->Pen->Mode = pmNot;
        PaintBox->Canvas->Brush->Style = bsClear;
        PaintBox->Canvas->MoveTo(Startpos.x, Startpos.y);
        PaintBox->Canvas->LineTo(Endpos.x, Endpos.y);
        Endpos.x = X; Endpos.y = Y;
        MCanvas = new TMetafileCanvas(Mfile, 0);
        MCanvas->Draw(0, 0, Mfile);
        MCanvas->MoveTo(Startpos.x, Startpos.y);
        MCanvas->LineTo(Endpos.x, Endpos.y);
        delete MCanvas;
        break; }
    case 2: {
        // ...etcetera drawing options here
    }
    PaintBoxPaint(Sender);
  }

Quote:}

And the following OnPaint event:

void __fastcall TMainForm::PaintBoxPaint(TObject *Sender)
{
  PaintBox->Canvas->FillRect(Rect(0,0,PaintBox->Width, PaintBox->Height));
  PaintBox->Canvas->Draw(0, 0, Mfile);

Quote:}

The above works fine for drawing a "* banding" line, but strangely
every time the OnMouseUp and OnPaint events are fired it seems that the
showed metafile is shrinking by one pixel in size. The help file states
that an *.emf file, Mfile in this case, is keeping track if the sizing
internally, but somehow that isn't enough obviously.
Has anybody a solution for this problem?

--
Greetings from sunny Amsterdam

                Jan


http://www.veryComputer.com/~bijster

 
 
 

TMetafile and TMetafileCanvas sizing

Post by J.A. Bijsterbosc » Fri, 04 Sep 1998 04:00:00


Hello All,



It seems that this question is more difficult then I thought, or perhaps I
did not phrase it clearly enough. However I've still not found a solution
so lets give it another try.

According to the online help in BCB1 standard edition to create an Enhanced
Metafile (*.emf) from scratch one has to do the following:

TMetafile *Mfile = new TMetafile();
TMetafileCanvas *MCanvas = new TMetafileCanvas(Mfile, 0);
// Now draw something
MCanvas->Rectangle(10, 10, 100, 100);
// deleting TMetafileCanvas will put the changes int the TMetafile for
'playing'
delete MCanvas
// Now show the drawing in the TMetafile
PaintBox->Canvas->Draw(0, 0, Mfile);

So far so good, but now comes the problem noted in the header of this post.
If one wants to add to the drawing stored in the the TMetafile one has to
do the following:

TMetafileCanvas *MCanvas = new TMetafileCanvas(Mfile, 0);
// Copy the drawing already in the TMetafile to the canvas
MCanvas->Draw(0, 0, Mfile);
// Add something to the drawing
MCanvas->Ellipse(80, 80, 150, 150);
delete MCanvas;
PaintBox->Canvas->Draw(0, 0, Mfile);

This all looks quite straight forward, but somehow this second step does
make the drawing shrink approximate one pixel in height and width allmost
every time a new TMetafileCanvas is created. I presume this has to do with
some resolution rounding effects between inches and millimeters somewhere,
but i've not been able to find out where, or how to fix this.

Please, can anybody help me out here..?

--
Greetings from sunny Amsterdam

                Jan


http://home.worldonline.nl/~bijster

 
 
 

TMetafile and TMetafileCanvas sizing

Post by L.J. Wisch » Fri, 04 Sep 1998 04:00:00



>It seems that this question is more difficult then I thought, or perhaps I
>did not phrase it clearly enough. However I've still not found a solution
>so lets give it another try.
>TMetafileCanvas *MCanvas = new TMetafileCanvas(Mfile, 0);
>// Copy the drawing already in the TMetafile to the canvas
>MCanvas->Draw(0, 0, Mfile);
>// Add something to the drawing
>MCanvas->Ellipse(80, 80, 150, 150);
>delete MCanvas;
>PaintBox->Canvas->Draw(0, 0, Mfile);
>This all looks quite straight forward, but somehow this second step does
>make the drawing shrink approximate one pixel in height and width allmost

I have had nothing but grief with the built in TMetafile. I believe that
it makes assumptions that are often unhelpful, and I don't believe its
resizing and saving stuff. I reckon that using the plain Windows API for
metafiles is more likely to result in success.

When you create an EMF without specifying dimensions, Windows will attempt
to figure out its size. (Look in the Windows API for 'Crea*hMetaFile'
at the rect parameter). 'Warning' it says: 'if at all possible you should
specify this parameter. If you don't then crocodiles might leap out of
your screen and gobble you up whole'. (I made up the last bit).

I bet that Windows is recalculating the size of the emf each time. And
because recalculation is a tricky thing, based on happenstance and the
GDI; and because there are lots of comments in the metafile overview about
whether or not the bottom right is included, I reckon this is getting it
wrong.

So: try using the Windows API itself, and try specifing RECT parameters
yourself.

Your original aim, you said, was a drawing program for creating EMF files.
My approach was to use plain old CorelDraw4, copying pictures to the
clipboard and pasting them as EMF. Or you could even use the plain old
TMetafile to load a WMF and save it as an EMF.

--

 
 
 

TMetafile and TMetafileCanvas sizing

Post by CF » Mon, 14 Sep 1998 04:00:00



> Hello All,



> It seems that this question is more difficult then I thought, or perhaps I
> did not phrase it clearly enough. However I've still not found a solution
> so lets give it another try.

> According to the online help in BCB1 standard edition to create an Enhanced
> Metafile (*.emf) from scratch one has to do the following:

> TMetafile *Mfile = new TMetafile();
> TMetafileCanvas *MCanvas = new TMetafileCanvas(Mfile, 0);
> // Now draw something
> MCanvas->Rectangle(10, 10, 100, 100);
> // deleting TMetafileCanvas will put the changes int the TMetafile for
> 'playing'
> delete MCanvas
> // Now show the drawing in the TMetafile
> PaintBox->Canvas->Draw(0, 0, Mfile);

> So far so good, but now comes the problem noted in the header of this post.
> If one wants to add to the drawing stored in the the TMetafile one has to
> do the following:

> TMetafileCanvas *MCanvas = new TMetafileCanvas(Mfile, 0);
> // Copy the drawing already in the TMetafile to the canvas
> MCanvas->Draw(0, 0, Mfile);
> // Add something to the drawing
> MCanvas->Ellipse(80, 80, 150, 150);
> delete MCanvas;
> PaintBox->Canvas->Draw(0, 0, Mfile);

> This all looks quite straight forward, but somehow this second step does
> make the drawing shrink approximate one pixel in height and width allmost
> every time a new TMetafileCanvas is created. I presume this has to do with
> some resolution rounding effects between inches and millimeters somewhere,
> but i've not been able to find out where, or how to fix this.

> Please, can anybody help me out here..?

> --
> Greetings from sunny Amsterdam

>                 Jan


> http://home.worldonline.nl/~bijster

Maybe this is happening....?

Say your canvas is Canvas->Width=100; Canvas->Height=100;
You can only Draw to 0,0 - 99,99 not to 100,100
That's the way it should be.

~Chris
--
Get Net Scoreboard 1.0 for FBPro at
http://www.erols.com/lyrixx/

 
 
 

TMetafile and TMetafileCanvas sizing

Post by J.A. Bijsterbosc » Tue, 15 Sep 1998 04:00:00


Hello Chris,



> > Hello All,



> > It seems that this question is more difficult then I thought, or
perhaps I
> > did not phrase it clearly enough. However I've still not found a
solution
> > so lets give it another try.

[ example from BCB1 online help snipped ]

Quote:> > ....but somehow this second step does
> > make the drawing shrink approximate one pixel in height and width
allmost
> > every time a new TMetafileCanvas is created.

> > Please, can anybody help me out here..?

> Maybe this is happening....?

> Say your canvas is Canvas->Width=100; Canvas->Height=100;
> You can only Draw to 0,0 - 99,99 not to 100,100
> That's the way it should be.

Could it be coincidence<g>, I just read about the above behaviour of the
GDI in a book I bought on a sale called "The Black Art of Windows Game
Programming".
Coming from a Dos programming background, it's quite informative geting
into the windows ways of doing things. Not only the graphics part I must
add to say.

This said, I'll have a look if this is what's screwing things up... ;-))

Quote:> ~Chris

--
Greetings from rainy Amsterdam

                Jan


http://home.worldonline.nl/~bijster

 
 
 

1. TMetafile and TMetafileCanvas objects

When creating a TMetafile object, and passing it to a TMetafileCanvas
object, I cannot find in the MetafileCanvas any reference as to the size
(in units) of the canvas.  Metafile has size expressed in MMHeight,
MMWidth.  I'd like to use these to draw a graphic (with axis) of timed data
(X axis it time, Y Axis is kilowatts).

The problem is this: I need sufficient precision on both axis (up to 8760
point on X).  Setting the Metafile MMHeight and MMWidth values can give me
this precision.

Now, what are the limits on MMHeight and MMWidht, and how to they translate
in the MetafileCanvas when, for instance, you have

TMetafile *pMetafile = new TMetafile;

Metafile->MMHeight = 50000;
Metafile->MMWidth = 50000;

TMetafileCanvas *pCanvas = new TMetafileCanvas(Metafile, 0);

When drawing on the MetafileCanvas, I cannot find any reference to the
Height and Width of the Canvas, which I could use to maximize the use of
the canvas

Any ideas ?

Denis Deslauriers

2. Molecular Modeling Problem with RE

3. Playing TMetafile to TMetafileCanvas

4. Unsharp Mask Filter

5. TMetaFile & TMetaFileCanvas (NOT the linking problem)

6. Where can I find Adobecap.exe CODEC???

7. TMetafile and TMetafilecanvas

8. cloth

9. problems with TMetafile & TMetafilecanvas

10. Tmetafilecanvas size

11. Pasting Copied Shape (Metafile) into a TMetafile, with correct size

12. TMetafile Sizing

13. OpenGL context on Tmetafilecanvas