i defined my own 24 bit data type like this
class _24bit{
public byte[] _value = new byte[3];
}
i have data in binary in a _24bit data array
_24bit []data = new _24bit
i declared my bitmap as
Bitmap b = new Bitmap(columns / 3, rows, PixelFormat.Format24bppRgb);
but when i declare this to get a row in the bitmap
_24bit *row = (_24bit *)bmd.Scan0 + (j * bmd.Stride);
i get this compile error
Cannot take the address of, get the size of, or declare a pointer to a managed type (‘mynamespace._24bit’)
How can i proceed with my own 24bit data type ?
You really can’t declare pointers to managed reference types (and your _24bit class is managed reference type). Even if you declare
_24bitas astruct(making it a value type), it still contains a reference to a byte array (not byte array itself, only a reference, which makes size of this struct larger than 24 bits). You can declare you array asfixedandunsafeto fix that. You also might need to specifyStructLayoutattribute:Note, that you can only access content of this struct in
unsafecontext. Or drop array declaration at all:Alternatively, you can recreate bitmap in terms of your data structures and copy data from unmanaged memory to your data structures. Something like