Wie präsentiere ich eine Metafile -Rekord von CreatePenindirect aus einem Byte -Array?

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

  •  21-09-2019
  •  | 
  •  

Frage

Ich brauche ein wenig Hilfe bei der Definition des folgenden Windows -GDI -Typs in C#. Ich habe die Daten in Form von a byte[] In C#, und ich muss es irgendwie als Folgendes in C#marschallieren oder wirken. Bitte sehen Sie meine andere Frage, wie ich die Antwort auf die Polylinie bekam. Dies ist der Typ:

NAME

META_CREATEPENINDIRECT

Nächster API -Anruf

#include <windows.h>
HPEN32 CreatePenIndirect(const LOGPEN32 *pen);

typedef struct tagLOGPEN
{
    UINT        lopnStyle;
    POINT       lopnWidth;
    COLORREF    lopnColor;
} LOGPEN;

BEZEICHNUNG

U16     Value
0       lopnStyle
1       lopnWidth
2, 3    lopnColor

Lopncolor ist die Farbe des Stifts, Lopnwidth ist die Breite des Stifts. Wenn die Breite des Stifts> 1 ist, aber der Lopnstyle nicht fest ist, wird Lopnstyle ignoriert und trotzdem auf fest eingestellt.

lopnstyle kann einer von sein PS_SOLID, PS_DASH, PS_DOT, PS_DASHDOT, PS_DASHDOTDOT, PS_NULL, PS_INSIDEFRAME, PS_USERSTYLE, PS_ALTERNATE. Schauen Sie sich die Quelle dafür an, dass sie tatsächlich meinen.

Es gibt auch eine Reihe von Flaggen und Masken, die auch in Lopnstyle gefunden werden können PS_STYLE_MASK, PS_ENDCAP_ROUND, PS_ENDCAP_SQUARE, PS_ENDCAP_FLAT, PS_ENDCAP_MASK, PS_JOIN_ROUND, PS_JOIN_BEVEL, PS_JOIN_MITER, PS_JOIN_MASK, PS_COSMETIC, PS_GEOMETRIC, PS_TYPE_MASK, Schauen Sie sich die Quelle erneut an, um diese herauszufinden.


UPDATE: Dies ist so nah wie möglich:

fixed (byte* b = dataArray)
{
    byte* ptr = (byte*)b;
    // Get style
    l_nStyle = (ushort)*(ptr);
    ++ptr;
    // Get width
    l_nWidth = (ushort)*(++ptr);
    ++ptr;
    // skip one ushort
    ++ptr; ++ptr;
    // Get RGB colors
    l_nColorR = (ushort)*(++ptr);
    l_nColorG = (ushort)*(++ptr);
    l_nColorB = (ushort)*(++ptr);
}
War es hilfreich?

Lösung

byte[] buffer;
int style = BitConverter.ToUInt16(buffer, 0);
int width = BitConverter.ToUInt16(buffer, 2);
var color = Color.FromArgb(buffer[4], buffer[5], buffer[6]);
var pen   = new Pen(color, width)
{
    DashStyle = ..., // set style
    StartCap = ...,
    EndCap = ...
};

(Ungetestet)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top