I'm using a BitmapData
object aquired using Bitmap.LockBits
to read and write pixel data quickly. The functionality is encapsulated in a class. Can I store refs to the Scan0
and Stride
of a BitmapData
object or should I read it every time I need to access a pixel? Based on my usage, the same class object can be active for hours, during this period of time would the Scan0
/Stride
change? Or can I store refs to them in the class to reduce property accesses?
Access every time (a bit slower)
public BitmapData Data;
byte* pixByte = (byte*)BmpData.Scan0 + (Y * BmpData.Stride) + (X * 3); // access pixel of 24bpp image
Storing refs (is this possible?)
public BitmapData Data;
public IntPtr Scan0;
public int Stride;
byte* pixByte = (byte*)Scan0 + (Y * Stride) + (X * 3); // access pixel of 24bpp image