微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CodeGo.net>如何将旧式的Windows图元文件写入文件

我可以生成一个旧的(未增强的)图元文件.如何将其写入磁盘,使其成为正确的.wmf文件

解决方法:

Petzold doesn’t mention it,但是有一个将图元文件写入磁盘的约定:在图元文件数据前加上WmfPlaceableFileHeader structure.显然,这是invented by Aldus, back int the day,称为“可放置图元文件”.

[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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐