Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to properly address 16bpp with pointers in C#
    primarykey
    data
    text
    <p>I am trying to copy camera metadata into a Bitmap, and seing as each value in the metadata is a 16bit (or ushort) I thought it would be sensible to display it in a 16bpp garyscale Bitmap. The code I wrote is as follows:</p> <pre><code>// Getting the metadata from the device metaData = new DepthMetaData(); dataSource.GetMetaData(metaData); // Setting up bitmap, rect and data to use pointer Bitmap bitmap = new Bitmap(metaData.XRes, metaData.YRes, PixelFormat.Format16bppGrayScale); Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); BitmapData data = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format16bppGrayScale); // Pointer pointing to metadata ushort* ptrMetaData = (ushort*)dataSource.DepthMapPtr.ToPointer(); lock(this) { // Runs through the whole bitmap and assigns the entry in the metadata // to a pixel for (int y = 0; y &lt; bitmap.Height; ++y) { ushort* ptrDestination = (ushort*)data.Scan0.ToPointer() + y * data.Stride; for (int x = 0; x &lt; bitmap.Width; ++x, ++ptrMetaData) { ptrDestination[x] = (ushort)*ptrMetaData; } } } // Once done unlock the bitmap so that it can be read again bitmap.UnlockBits(data); </code></pre> <p>When running the Metadata's XRes = 640 and YRes = 480. The code throws a memory access exception in the for-loops on "ptrDestination[x] = (ushort)*ptrMetaData;" after only running though 240, half the total, lines.</p> <p>I used this with 8bpp where I reduced the resolution and it worked nicely, so I don't see why it should not here. Maybe someone finds the problem.</p> <p>Thanks already</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload