function MetafileToRtf(Metafile: TMetafile: OutputStream: TStream);
type
TMetafileHeader =
packed record
Key: Cardinal;
Handle: SmallInt;
Box: TSmallRect;
Inch: Word;
Reserved: Cardinal;
CheckSum: Word;
end;
var
MemoryStream: TMemoryStream;
DataSize: int64;
Pre, Suf:
string;
begin
MemoryStream := TMemoryStream.Create;
try
Metafile.Enhanced := false;
Metafile.SaveToStream(MemoryStream);
MemoryStream.Position := SizeOf(TMetafileHeader);
DataSize := MemoryStream.Size - MemoryStream.Position;
{ \picw und \pich - Darstellungsgröße in 1/100 mm
\picwgoal und \pichgoal - Originalgröße in Twips
\picscalex und picscaley - Verhältnis Darstellungsgröße:Originalgröße in Prozent
}
Pre := Format('
{\pict\wmetafile8\picw%d\pich%d' +
'
\picscalex%d\picscaley%d\picwgoal%d\pichgoal%d\bin%d'#13#10,
[MulDiv(Metafile.Width, 2560, Metafile.Inch),
MulDiv(Metafile.Height, 2560, Metafile.Inch),
100, 100,
MulDiv(Metafile.Width, 1440, Metafile.Inch),
MulDiv(Metafile.Height, 1440, Metafile.Inch),
DataSize]);
Suf := '
}';
OutputStream.WriteBuffer(Pre[1], Length(Pre));
OutputStream.CopyFrom(MemoryStream, DataSize);
OutputStream.WriteBuffer(Suf[1], Length(Suf));
finally
MemoryStream.Free;
end;
end;