• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

How to put shapes on top of a Metafiles?

I start with either a bmp, jpg, emf or wmf (main image), then I want to put shapes onto of this image and output it as emf.  What is the best way to do this and how do I control the corrdinates of an emf?  Can I put icons or another smaller image onto of this main image and output it as emf?

TIA
0
Khaki
Asked:
Khaki
  • 2
  • 2
1 Solution
 
Slick812Commented:
hello Khaki, You do not say why you need an EMF type of Image, The Emf image is a vector type of image, and you say you want to use A Bitmap for this image, and a Bitmap is a Raster type of image (raster images have a record for EVERY pixel in the image, for the pixel colors. . . A vector Image only has drawing functions recorded and is a compleatly different kind of medium). . If you draw Bitmaps on a EMF image it will Lose it's vector qualities,  , I always try not to put any rastor images (bitmaps) onto vector images(MetaFiles).

here is some code to put shapes on a EMF and save it to file.


procedure TForm1.sbut_MakeEmfClick(Sender: TObject);
var
Emf1: TMetaFile;
AryPt: array[0..3] of TPoint;
Bmp1: TBitmap;
begin
Emf1 := TMetafile.Create;
Bmp1 := TBitmap.Create;
try
Emf1.Enhanced := True;
Emf1.Width := 120;
Emf1.Height := 120;
Emf1.Transparent := True;

Bmp1.Canvas.Brush.Color := clBlack;
Bmp1.Width := 47;
Bmp1.Height := 27;

with TMetafileCanvas.Create(Emf1, 0) do
try
  Brush.Color := clRed;
  Rectangle(56,18,110,40);
  Brush.Color := clBlue;
  Ellipse(60,80,110,110);
  Pen.Color := clGreen;
  Brush.Color := clAqua;
  AryPt[0].x := 4;
  AryPt[0].y := 10;
  AryPt[1].x := 60;
  AryPt[1].y := 30;
  AryPt[2].x := 60;
  AryPt[2].y := 50;
  AryPt[3].x := 4;
  AryPt[3].y := 60;
  Polygon(AryPt);
{if you put a bitmap on a EMF it will NOT streatch the
bitmap pixels like a vector image and your file size will increase}
  Draw(4,90, Bmp1);
{if you cover an EMF with a bit map, it will act like a bitmap
you may as well use a Bitmap instead}
  {you can draw a TIcon with
   Draw(1,1, Icon1);}
  finally
  Free
  end;
PaintBox1.Canvas.Draw(20,20, Emf1);
Emf1.SaveToFile('E:\Emf1.emf');
Finally
FreeAndNil(Emf1);
FreeAndNil(Bmp1);
end;
end;

- - - - - - - - - - - - - - - - - - - - - - - - -  -

if you are going to draw Bitmaps and Icons on this, maybe you should just use a Bitmap?
ask questions if you need more info
0
 
KhakiAuthor Commented:
Is there a way to resize Metafile? Eg convert it to bmp or jpeg and resize it to 50% of original size?
0
 
KhakiAuthor Commented:
Is there a way to resize Metafile? Eg convert it to bmp or jpeg and resize it to 50% of original size?
0
 
Slick812Commented:
look in delphi help for "StretchDraw" you can draw a Bitmap onto a Smaller Bitmap with StretchDraw, ,  since MetaFiles are vector images you can just resize them. . . if you can not figure this out I'll give you some code, there are Example code in the delphi help, , , there are plenty of pages here at EE about these things, , ,
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now