gpt4 book ai didi

c# - 如何将旧式 Windows 图元文件写入文件

转载 作者:可可西里 更新时间:2023-11-01 09:20:15 26 4
gpt4 key购买 nike

我可以生成一个旧的(未增强的)图元文件。我怎样才能将它写入磁盘以使其成为正确的 .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);

关于c# - 如何将旧式 Windows 图元文件写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25560157/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com