Original Post
Hey guys, i was wondering, i have the following code: where public IntPtr pixels; This pointer actually points to a unsigned char array in C. How can i access this array in C#? I do not know how many pixels are avaible up front, so i would somehow have to do something at runtime. Kind regards
[StructLayout( LayoutKind.Sequential )]
private struct GDImage
{
public IntPtr pixels;
public int sx;
public int sy;
public int colorsTotal;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=GD_MAX_COLORS )]
public int[] red;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=GD_MAX_COLORS )]
public int[] green;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=GD_MAX_COLORS )]
public int[] blue;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=GD_MAX_COLORS )]
public int[] open;
public int transparent;
public IntPtr polyInts;
public int polyAllocated;
public IntPtr brush;
public IntPtr tile;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=GD_MAX_COLORS )]
public int[] brushColorMap;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=GD_MAX_COLORS )]
public int[] tileColorMap;
public int styleLength;
public int stylePos;
public IntPtr style;
public int interlace;
public int thick;
[MarshalAs( UnmanagedType.ByValArray, SizeConst=GD_MAX_COLORS )]
public int[] alpha;
public int trueColor;
public IntPtr tpixels;
public int alphaBlendingFlag;
public int saveAlphaFlag;
private static Hashtable mFieldOffsets;
static GDImage()
{
// Cache field offsets for faster lookup
mFieldOffsets = new Hashtable();
Type t = typeof(GDImage);
foreach (System.Reflection.FieldInfo field in t.GetFields())
{
mFieldOffsets[field.Name] = Marshal.OffsetOf(t, field.Name).ToInt32();
}
}
/// <summary>
/// Returns the offset in bytes from the start of the GDImage structure
/// to the given field
/// </summary>
/// <param name="field">Field name</param>
/// <returns>Offset in bytes</returns>
public static int GetOffset(string field)
{
return (int)mFieldOffsets[field];
}
}