我對低級編程沒有經驗,我需要這段代碼才能使用[StructLayout(LayoutKind.Explicit)]。我的網站運行在共享主機和中等信任。 所以它不會運行,如果這個代碼在那裏。將[StructLayout]替換爲不使用System.Runtime.InteropServices的內容?
更新: 我正在使用這個裏面的八叉樹來量化PNG文件。
有沒有人知道工作?
更新 這裏=>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); }
}
}
你想做什麼?你不能只使用`Bitmap`類嗎? – 2009-07-08 17:33:41
您能否介紹一下爲什麼/如何使用非託管代碼? – 2009-07-08 17:34:07
這似乎是他試圖與來自其他來源的數據進行交互,使用不同的字節順序 – ShuggyCoUk 2009-07-08 18:05:09