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

  • Home
  • SEARCH
  • 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 6112339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:44:04+00:00 2026-05-23T14:44:04+00:00

This may well have come up before but the following code is taken from

  • 0

This may well have come up before but the following code is taken from an MSDN example I am modifying. I want to know how I can iterate through the contents of the buffer which contains data about a bitmap and print out the colors. Each pixel is 4 bytes of data so I am assuming the R G B values account for 3 of these bytes, and possibly A is the 4th.

What is the correct C++ syntax for the pointer arithmetic required (ideally inside a loop) that will store the value pointed to during that iteration in to a local variable that I can use, eg. print to the console.

Many thanks

PS. Is this safe? Or is there a safer way to read the contents of an IMFMediaBuffer? I could not find an alternative.

Here is the code:

hr = pSample->ConvertToContiguousBuffer(&pBuffer); // this is the BitmapData
    // Converts a sample with multiple buffers into a sample with a single IMFMediaBuffer which we Lock in memory next...

    // IMFMediaBuffer represents a block of memory that contains media data

    hr = pBuffer->Lock(&pBitmapData, NULL, &cbBitmapData);  // pBuffer is IMFMediaBuffer
    /* Lock method gives the caller access to the memory in the buffer, for reading or writing:
    pBitmapData - receives a pointer to start of buffer
    NULL - receives the maximum amount of data that can be written to the buffer. This parameter can be NULL.
    cbBitmapData - receives the length of the valid data in the buffer, in bytes. This parameter can be NULL.
    */
  • 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-23T14:44:05+00:00Added an answer on May 23, 2026 at 2:44 pm

    I solved the problem myself and thought it best to add the answer here so that it formats correctly and maybe others will benefit from it. Basically in this situation we use 32 bits for the image data and what is great is that we are reading raw from memory so there is not yet a Bitmap header to skip because this is just raw color information.

    NOTE: Across these 4 bytes we have (from bit 0 – 31) B G R A, which we can verify by using my code:

      int x = 0;
    
        while(x < cbBitmapData){
    
            Console::Write("B: {0}", (*(pBitmapData + x++)));
            Console::Write("\tG: {0}", (*(pBitmapData + x++)));
            Console::Write("\tR: {0}", (*(pBitmapData + x++)));
            Console::Write("\tA: {0}\n", (*(pBitmapData + x++)));
        }
    

    From the output you will see that the A value is 0 for each pixel because there is no concept of transparency or depth here, which is what we expect.

    Also to verify that all we have in the buffer is raw image data and no other data I used this calculation which you may also find of use:

    Console::Write("no of pixels in buffer: {0} \nexpected no of pixels based on dimensions:{1}", (cbBitmapData/4), (m_format.imageWidthPels * m_format.imageHeightPels) );
    

    Where we divide the value of cbBitmapData by 4 because it is a count of the bytes, and as aforementioned for each pixel we have a width of 4 bytes (32-bit DWORDS in actual fact because the length of a byte is not always strictly uniform across hardware apparently!?). We compare this to the image width multiplied by its height. They are equal and thus we have just pixel color information in the buffer.

    Hope this helps someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question may well have been asked before but I didn't find anything whilst
I have this linq query that works well (although it may be written better,
This may well be simple, but I'm new to Drupal. The organization I work
I know this question may well be the silliest question you've heard today, but
I have a question that may have been answered over 9000 times before but
this may well be a very basic question, but I haven't been able to
Well, I'm learning Scala so this question may be too basic for most people.
This may be a no-brainer for the WPF cognoscenti, but I'd like to know
This may seem like a daft question, but i was wondering about how to
This may be simple one, but 5 mins of Googling didn't give me the

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.