Como faço para analisar um recorde de metafile de poliina em uma matriz de bytes?

StackOverflow https://stackoverflow.com/questions/1773953

  •  21-09-2019
  •  | 
  •  

Pergunta

Preciso de uma pequena ajuda para definir o seguinte tipo de GDI do Windows em C#. Eu tenho os dados na forma de um byte[] em C#, e eu preciso de alguma forma marechal ou lançá -lo como o seguinte em C#. Suponho que preciso definir a estrutura adequada? Este é o tipo:

NOME

META_POLYLINE

Chamada da API mais próxima

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

DESCRIÇÃO

    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

Uma poliina é uma lista de pontos. Ao contrário de um polígono, uma poliina é sempre preenchida e pode ser aberta.

Foi útil?

Solução

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

(Não testado)

Outras dicas

Você já olhou para o Entrada de Polyline no pinvoke.net ainda?

Ok, um recorde de metafile para uma poliina ... você pode querer tentar fazer um Buffer.BlockCopy Da matriz de bytes a um UInt16 variedade.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top