Mirror

How to save a metafile displayed in a TImage as a bitmap (Views: 25)


Problem/Question/Abstract:

How to save a metafile displayed in a TImage as a bitmap

Answer:

Try to give the width and height of the image in the bitmap before drawing the metafile or use the assign method of the bitmap to get the results you want. For example:

{ ... }
var
  aBitmap: TBitmap;
begin
  aBitmap := TBitmap.Create;
  aBitmap.width := Image.picture.width;
  aBitmap.height := Image1.picture.height;
  try
    aBitmap.Canvas.Draw(0, 0, Image1.Picture.Metafile);
    abitmap.SaveToFile('D:\temp\mybit.bmp');
  finally
    aBitmap.free;
  end;

or try:

{ ... }
var
  aBitmap: TBitmap;
begin
  aBitmap := TBitmap.Create;
  try
    aBitmap.assign(image1.picture.graphic);
    aBitmap.SaveToFile('D:\temp\mybit.bmp');
  finally
    aBitmap.free;
  end;

<< Back to main page