如何编写一个老式的Windows图元到一个文件 [英] How to write an old-style Windows metafile to a file
本文介绍了如何编写一个老式的Windows图元到一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以生成一个老(未增强)图元文件。我怎样才能把它写入磁盘,使其正确的.WMF文件
I can generate an old (not enhanced) metafile. How can I write it to disk so that it is a proper .wmf file?
推荐答案
的彼佐尔德没有提到它,但写图元文件到磁盘上的约定:前缀与 WmfPlaceableFileHeader结构图元文件的数据。显然,这是由Aldus发明的,回来的int日和被称为放置的图元文件。
Petzold doesn't mention it, but there is a convention for writing metafiles to disk: prefix the metafile data with the WmfPlaceableFileHeader structure. Apparently this was invented by Aldus, back int the day and is called a "placeable metafile".
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct WmfPlaceableFileHeader
{
public uint key; // 0x9aC6CDD7
public ushort hmf;
public ushort bboxLeft;
public ushort bboxTop;
public ushort bboxRight;
public ushort bboxBottom;
public ushort inch;
public uint reserved;
public ushort checksum;
}
Win32.WmfPlaceableFileHeader header = new Win32.WmfPlaceableFileHeader();
const ushorttwips_per_inch = 1440;
header.key = 0x9aC6CDD7; // magic number
header.hmf = 0;
header.bboxLeft = 0;
header.bboxRight = width_in_inches * twips_per_inch;
header.bboxTop = 0;
header.bboxBottom = height_in_inches * twips_per_inch;
header.inch = twips_per_inch;
header.reserved = 0;
// Calculate checksum for first 10 WORDs.
ushort checksum = 0;
byte[] header_bytes = StructureToByteArray(header);
for (int i = 0; i < 10; i++)
checksum ^= BitConverter.ToUInt16(header_bytes, i * 2);
header.checksum = checksum;
// Construct the file in-memory.
header_bytes = StructureToByteArray(header);
file_contents.Write(header_bytes, 0, header_bytes.Length);
file_contents.Write(metafile_bytes, 0, metafile_bytes.Length);
这篇关于如何编写一个老式的Windows图元到一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文