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 4083228
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:17:12+00:00 2026-05-20T18:17:12+00:00

I read in another thread, that I can read a single pixel with Texture.Lock

  • 0

I read in another thread, that I can read a single pixel with Texture.Lock / Unlock, but I need to write the pixels back to the texture after reading them, this is my code so far

unsigned int readPixel(LPDIRECT3DTEXTURE9 pTexture, UINT x, UINT y)
{
    D3DLOCKED_RECT rect;
    ZeroMemory(&rect, sizeof(D3DLOCKED_RECT));
    pTexture->LockRect(0, &rect, NULL, D3DLOCK_READONLY);
    unsigned char *bits = (unsigned char *)rect.pBits;
    unsigned int pixel = (unsigned int)&bits[rect.Pitch * y + 4 * x];
    pTexture->UnlockRect(0);
    return pixel;
}

So my questions are:

- How to write the pixels back to the texture?  
- How to get the ARGB values from this unsigned int? 

((BYTE)x >> 8/16/24) didnt work for me (the returned value from the function was 688)

  • 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-20T18:17:12+00:00Added an answer on May 20, 2026 at 6:17 pm

    1) One way is to use a memcpy:

    memcpy( &bits[rect.Pitch * y + 4 * x]), &pixel, 4 );
    

    2) There are a number of different ways. The simplest is to define a struct as follows:

    struct ARGB
    {
        char b;
        char g;
        char r;
        char a;
    };
    

    Then change your pixel loading code to the following:

    ARGB pixel;
    memcpy( &pixel, &bits[rect.Pitch * y + 4 * x]), 4 );
    
    char red = pixel.r;
    

    You can also obtain all the values using masks and shifts. e.g

    unsigned char a = (intPixel >> 24);
    unsigned char r = (intPixel >> 16) & 0xff;
    unsigned char g = (intPixel >>  8) & 0xff;
    unsigned char b = (intPixel)       & 0xff;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In .Net you can read a string value into another data type using either
I want to read an xml file, apply a transform, then write to another
I am trying to read an XML-file from another server. However the the company
What's the most efficient way to read a stream into another stream? In this
I'm trying to read the data in a Win32 ListView owned by another process.
Of the two methods below, which do you prefer to read? Is there another
I read this PHP RegEx page , but either I'm missing something, misreading something,
I read somewhere once that the modulus operator is inefficient on small embedded devices
Everything that I read about sockets in .NET says that the asynchronous pattern gives
Edit: From another question I provided an answer that has links to a lot

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.