繁体   English   中英

如何从字节数组中解析折线图元文件记录?

[英]How do I parse a polyline metafile record out of a byte array?

在C#中定义以下Windows GDI类型时,我需要一些帮助。 我在C#中具有byte[]形式的数据,我需要以某种方式将其编组或转换为C#中的以下内容。 我想我需要定义适当的结构? 这是类型:

名称

META_POLYLINE

NEAREST API呼叫

#include <windows.h>
BOOL32 Polyline
(
    HDC32 hdc,
    const POINT32 *pt,
    INT32 count
);

描述

U16 array no                Value
    --------------------------- --------------
    0                           no of points
    1 each odd until the end    x of the point
    2 each even until the end   y of the point

折线是点的列表。 与多边形不同,折线始终是未填充的,并且可以打开。

您是否查看过PInvoke.net上的Polyline条目

好的,一条折线的元文件记录...您可能想尝试将Buffer.BlockCopy从字节数组转换为UInt16数组。

byte[] buffer;
fixed (byte* b = buffer)
{
   ushort* ptr = (ushort*)b;
   int count = (int)*ptr;
   var points = new Point[count];
   for (int i = 0; i < count; i++)
   {
       int x = (int)*(++ptr);
       int y = (int)*(++ptr);
       points[i] = new Point(x, y);
   }
}

(未经测试)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM