Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7563475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:40:32+00:00 2026-05-30T13:40:32+00:00

I am trying to copy camera metadata into a Bitmap, and seing as each

  • 0

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:

// 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 < bitmap.Height; ++y)
    {
        ushort* ptrDestination = (ushort*)data.Scan0.ToPointer() + y * data.Stride;
        for (int x = 0; x < bitmap.Width; ++x, ++ptrMetaData)
        {
            ptrDestination[x] = (ushort)*ptrMetaData;
        }
    }
}

// Once done unlock the bitmap so that it can be read again
bitmap.UnlockBits(data);

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.

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.

Thanks already

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:40:34+00:00Added an answer on May 30, 2026 at 1:40 pm
        ushort* ptrDestination = (ushort*)data.Scan0.ToPointer() + y * data.Stride;
    

    The data.Stride value is expressed in bytes, not ushorts. So the pointer is off by a factor of 2 so it bombs at bitmap.Height/2. Your for loops are broken, swap bitmap.Width and bitmap.Height. The lock keyword doesn’t make much sense here, you are accessing thread-local data, other than dataSource. Fix:

    for (int y = 0; y < bitmap.Height; ++y)
    {
        ushort* ptrDestination = (ushort*)data.Scan0.ToPointer() + y * data.Stride / 2;
        for (int x = 0; x < bitmap.Width; ++x, ++ptrMetaData)
        {
            ptrDestination[x] = (ushort)*ptrMetaData;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to copy and paste a table from excel into a word document.
I'm trying to copy one form <input> field value to another form using jQuery.
I'm trying to copy a chunk from one binary file into a new file.
Trying to copy a database into a new database, using a PHP script that
i am trying to copy an custom sqlite database into android and it is
I'm trying to copy both an image from a file and text from a
I am trying to copy a header and a set of data to a
I am trying to copy a file from my remote server to my local.
I am trying to copy the contents of certain folders to another folder using
I'm trying to copy a directory using the Ant copy task. I am a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.