私は低レベルのプログラミングの経験がなく、[StructLayout(LayoutKind.Explicit)] を使用しないためにこのコードが必要です。私のサイトは共有ホスト上で中程度の信頼で実行されています。したがって、このコードがそこにあると実行されません。
更新: これを Octree 内で使用して、png ファイルを量子化しています。
誰かが回避策を知っていますか?
ここで新しい質問を更新=>マーシャリングなしで安全に画像の量子化を行う方法はありますか?
/// <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); }
}
}