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;
這是普通的舊EMF,你肯定也不會EMF + ? Afaik Delphi在股票發行版中沒有GDIplus組件 – 2010-04-22 07:52:12
嗯,不知道:) – Runner 2010-04-22 08:05:38
更新了答案。 – Runner 2010-04-22 08:17:38