TMetaFileCanvas不支持EMF+格式,但您可以使用GDI+完成您的任务。
以下是使用GDI+执行任务的示例代码:
type
PGdiplusStartupInput = ^TGdiplusStartupInput;
TGdiplusStartupInput = record
GdiplusVersion: Integer;
DebugEventCallback: Integer;
SuppressBackgroundThread: Integer;
SuppressExternalCodecs: Integer;
end;
function GdiplusStartup(var Token: Integer; InputBuf: PGDIPlusStartupInput; OutputBuf: Integer): Integer; stdcall; external 'gdiplus.dll';
procedure GdiplusShutdown(Token: Integer); stdcall; external 'gdiplus.dll';
function GdipCreateFromHDC(DC: HDC; var Graphics: Integer): Integer; stdcall; external 'gdiplus.dll';
function GdipDeleteGraphics(Graphics: Integer): Integer; stdcall; external 'gdiplus.dll';
function GdipLoadImageFromFile(Filename: PWChar; var GpImage: Integer): Integer; stdcall; external 'gdiplus.dll';
function GdipDrawImageRect(Graphics, Image: Integer; X, Y, Width, Height: Single): Integer; stdcall; external 'gdiplus.dll';
procedure LoadEMFPlus(const FileName: WideString; DC: HDC; Width, Height: Integer);
var
Token: Integer;
StartupInput: TGdiplusStartupInput;
Graphics: Integer;
Image: Integer;
begin
StartupInput.GdiplusVersion := 1;
StartupInput.DebugEventCallback := 0;
StartupInput.SuppressBackgroundThread := 0;
StartupInput.SuppressExternalCodecs := 0;
if GdiplusStartup(Token, @StartupInput, 0) = 0 then
begin
if GdipCreateFromHDC(DC, Graphics) = 0 then
begin
if GdipLoadImageFromFile(@FileName[1], Image) = 0 then
begin
GdipDrawImageRect(Graphics, Image, 0, 0, Width, Height);
end;
GdipDeleteGraphics(Graphics);
end;
GdiplusShutdown(Token);
end;
end;
你可以这样调用它:
procedure TForm1.Button1Click(Sender: TObject);
begin
LoadEMFPlus('EMFTest.emf',
PaintBox1.Canvas.Handle, PaintBox1.Width, PaintBox1.Height);
end;