Solved

Metafile to bitmap conversion

Posted on 1998-08-24
12
2,103 Views
Last Modified: 2013-11-19
We have a Metafile. We want to add some things to the "drawing". Metafile doesn't allow to change ???
Can we convert metafile to bitmap, so possibility to change, and then reconvert to metafile ?
How to do this ?
0
Comment
Question by:jvh042097
[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
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 4

Expert Comment

by:erajoj
ID: 1337495
Hi,
When you convert a graphical metafile to a bitmap, you loose all vector information in the file. So reconverting it to a vectorised metafile is "inpossible".
You can create a metafile DC and do your drawing onto it with normal GDI functions, and then save it as a metafile.
However, look through the common Delphi component/tips&tricks -sites before you get in to deep...
I have done lots of these things in MFC, but will look for something helpful in Delphi as soon as I can. Maybe there are others, GDI-Gurus, who are able to help...

/// John
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1337496
jvh?

? you can't change metafile???

Zif.
0
 
LVL 3

Accepted Solution

by:
Matvey earned 100 total points
ID: 1337497
Delphi ALLOWS DRAWING ON METAFILES:

The TMetafileCanvas object allows applications to create metafile images from scratch.
Use TMetafileCanvas as a surface on which to draw a metafile image. When the canvas is destroyed, it transfers the image into the metafile object provided to the canvas constructor. After the image is drawn on the canvas and the canvas is destroyed, the image is 'playable' in the metafile object. For example:

MyMetafile := TMetafile.Create;

with TMetafileCanvas.Create(MyMetafile, 0) do
try
Brush.Color := clRed;
Ellipse(0,0,100,100);
.
finally
Free;
end;
Form1.Canvas.Draw(0,0,MyMetafile); {1 red circle }

To add to an existing metafile image, create a metafile canvas and play the source metafile into the metafile canvas. For example:

{continued from previous example, so MyMetafile contains an image }

with TMetafileCanvas.Create(MyMetafile, 0) do
try
Draw(0,0,MyMetafile);
Brush.Color := clBlue;
Ellipse(100,100,200,200);
.
finally
Free;
end;
Form1.Canvas.Draw(0,0,MyMetafile); {1 red circle and 1 blue circle }

-----------------------------------------------
(Delphi help)

Bye!
Matvey
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 8

Expert Comment

by:ZifNab
ID: 1337498
jvh?

? you can't change metafile???

Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1337499
matvey is correct and I was too late to answer :-).

In order to draw on a metafile, you've to create a metafilecanvas.

Regards, Zif.
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337500
Sorry!
I've been debugging a MFC-app all day, so I didn't know what I was talking about. So here's how to do some simple metafile stuff, in Delphi:

var
  mfImage : TMetaFile;
  mfCanvas: TMetaFileCanvas;
  bmTest  : TBitmap;
  ...

  mfImage  := TMetaFile.Create;
  mfImage.LoadFromFile( 'BlahBlah.wmf' );
  mfCanvas := TMetaFileCanvas.Create( mfImage, 0 );
  with mfCanvas do
  begin
    Draw( 0, 0, mfImage );
    Pen.Color := clRed;
    MoveTo( 0, 0 ); // almost any old GDI-command here...
    LineTo( 100, 100 );
    bmTest := TBitmap.Create;
    bmTest.LoadFromFile( 'Blah.bmp' );
    Draw( 0, 0, bmTest );
    bmTest.Free;
  end;
  mfCanvas.Free;
  mfImage.SaveToFile( 'BlahBlahBlah.wmf' );
  mfImage.Free;
 
That's it. Easy, huh?

/// John
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337501
Hi Zif,
Just said that converting metafile to bitmap and back again is "impossible", unless you trace the bitmap, of course!

/// John
0
 

Expert Comment

by:aiming
ID: 1337502
hi, My Friend:
  At afternoon, i finished a program about BMP <==> .WMF/.EMF.
  I want use it at COOL 3D. but you want get it. so i'll free all Source.
  ^-^
================
full Source:
================
program bmp2wmf;

uses
  Graphics, SysUtils;

var aBmp : TBitmap;
    aWmf : TMetaFile;
    param1 : String;
    paramExt : String;
begin
  if ParamCount >= 1 then
    begin
      param1 := UpperCase(ParamStr(1));
      paramExt := ExtractFileExt(param1);
    end;
  if (ParamCount < 1) or
     (ParamCount > 2) or
     ((ParamCount = 2) and (UpperCase(ParamStr(2)) <> '/E')) or
     ((paramExt <> '.BMP') and (paramExt <> '.WMF') and (paramExt <> '.EMF')) then
    begin
      writeln('ERROR: Param Invalid!');
      writeln('Uses : Bmp2Wmf <.Bmp/.Wmf> [/E]');
      writeln('notes: Param [/E] Define ouput .EMF File format.');
      exit;
    end;

  aBmp := TBitmap.Create;
  aWmf := TMetaFile.Create;
  if paramExt = '.BMP'
    then
      begin
        aBmp.LoadFromFile(param1);
        aWmf.Width := aBmp.Width;
        aWmf.Height := aBmp.Height;
       if ParamCount = 2 then aWmf.Enhanced := true
                         else aWmf.Enhanced := false;

        with TMetaFileCanvas.CreateWithComment(aWmf,0,'Aiming''s Conver program','V1.0beta') do
          Try Draw(0,0,aBmp);
          Finally Free;
          end;
        if aWmf.Enhanced
          then aWmf.SaveToFile(copy(param1,1,pos('.',param1)) + 'EMF')
          else aWmf.SaveToFile(copy(param1,1,pos('.',param1)) + 'WMF');
      end
    else
      begin
        aWmf.LoadFromFile(param1);
        aBmp.Width := aWmf.Width;
        aBmp.Height := aWmf.Height;
        aBmp.Canvas.Draw(0,0,aWmf);
        aBmp.SaveToFile(copy(param1,1,pos('.',param1)) + 'BMP');
      end;
  aBmp.Destroy;
  aWmf.Destroy;
end.

about me:
================
a programmer from CHINA.
mail: aim_to@yahoo.com
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337503
Are you aiming at me? ;-)
If you are, then you're missing my point. ;->
What I meant was that converting a bitmapped image into a vectorised image is "impossible". At least not w/o major losses in quality.
I posed a metafile question in the MFC-group a while back, about antialiased VECTORISED metafile to bitmap convertion. Any pointers???

/// John
0
 

Expert Comment

by:aiming
ID: 1337504
to erajoj:
===========
I'm sorry. i can't find the message about antialiased VECTORISED metafile to bitmap convertion at MFC-group.  :-((

a correlative Mail to Ulead Company:
====================================
Dear Kevin Chen and all friends:
  thank you and you help me disposed of this questions about Use WMF/EMF File In COOL  3D  V2.  use Bmp2WMF.EXE translate into file, not include any vector data, It's   impossibility!   of   course, if  I  think Get .BMP Image' bound, I can convert to a vector, but, i think not. :-)
  and  other,  i hope, at COOL 3D' next version, can use .BMP File import. qua a thought,  can  convert  a bound to a vector.  (yes?).   in  the bargain, can disintegrate a WMF vector to many COOL 3D' Object, and these Object can build in a Group or some Groups. i nope future COOL 3D be able to this.
  thank your help. again.
===========================================
hope the mail can help you.
0
 

Author Comment

by:jvh042097
ID: 1337505
thanks for all (!) the answers, but let's stop all discussions now ?

Jan VAN HYFTE
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337506
Why? Isn't this a forum for discussion and problemsolving? :)

/// John
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
In this second Micro Tutorial in the series,  viewers will learn more basic shortcuts and functions of Illustrator. In this tutorial you will learn about the eyedropper tool, zoom , ellipses and more.
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

623 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