Ich habe keine Erfahrung mit Low-Level-Programmierung und ich brauche dieses Stück Code, um [StructLayout (LayoutKind.Explicit)] nicht zu verwenden. Meine Site wird auf einem freigegebenen Host und in mittlerer Vertrauenswürdigkeit ausgeführt. So wird es nicht ausgeführt, wenn dieser Code dort ist.Ersetzen Sie [StructLayout] durch etwas, das System.Runtime.InteropServices nicht verwendet?
Update: Ich benutze dies in einem Octree, um eine PNG-Datei zu quantisieren.
Kennt jemand eine Arbeit herum?
aktualisieren Neue Frage hier =>Is there any way to do Image Quantization safely and with no Marshalling?
/// <summary>
/// Struct that defines a 32 bpp colour
/// </summary>
/// <remarks>
/// This struct is used to read data from a 32 bits per pixel image
/// in memory, and is ordered in this manner as this is the way that
/// the data is layed out in memory
/// </remarks>
[StructLayout(LayoutKind.Explicit)]
public struct Color32
{
public Color32(IntPtr pSourcePixel)
{
this = (Color32)Marshal.PtrToStructure(pSourcePixel, typeof(Color32));
}
/// <summary>
/// Holds the blue component of the colour
/// </summary>
[FieldOffset(0)]
public byte Blue;
/// <summary>
/// Holds the green component of the colour
/// </summary>
[FieldOffset(1)]
public byte Green;
/// <summary>
/// Holds the red component of the colour
/// </summary>
[FieldOffset(2)]
public byte Red;
/// <summary>
/// Holds the alpha component of the colour
/// </summary>
[FieldOffset(3)]
public byte Alpha;
/// <summary>
/// Permits the color32 to be treated as an int32
/// </summary>
[FieldOffset(0)]
public int ARGB;
/// <summary>
/// Return the color for this Color32 object
/// </summary>
public Color Color
{
get { return Color.FromArgb(Alpha, Red, Green, Blue); }
}
}
Was möchten Sie tun? Können Sie nicht einfach die Bitmap-Klasse verwenden? –
Können Sie ein wenig Hintergrundinformationen darüber geben, warum/wie Sie nicht verwalteten Code verwenden? –
Es scheint, er versucht, mit Daten aus einer anderen Quelle mit einer anderen Byte-Reihenfolge zu interferieren – ShuggyCoUk