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

我只是一个虾纸丫 提交于 2019-12-11 15:03:15

问题


I need a little help in defining the following Windows GDI type in C#. I have the data in the form of a byte[] in C#, and I need to somehow marshal or cast it as the following in C#. I suppose I need to define the proper struct? This is the type:

NAME

META_POLYLINE

NEAREST API CALL

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

DESCRIPTION

    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

A polyline is a list of points. Unlike a polygon, a polyline is always unfilled, and can be open.


回答1:


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

(Untested)




回答2:


Have you looked at the Polyline entry on PInvoke.net yet?




回答3:


Okay, a metafile record for a polyline... You might want to try doing a Buffer.BlockCopy from the byte array to a UInt16 array.



来源:https://stackoverflow.com/questions/1773953/how-do-i-parse-a-polyline-metafile-record-out-of-a-byte-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!