簡體   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