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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:35:38+00:00 2026-06-12T16:35:38+00:00

Lately I got low level graphics programming job to do (implementing raster graphics algorithms).

  • 0

Lately I got low level graphics programming job to do (implementing raster graphics algorithms).
That’s why I started to look for tools (classes) which would be helpful to draw primitives (lines, rectangles, ellipses etc.) on the low level of abstraction (even using unsafe code).

I consider if I should implement my algorithms in WPF, WindowsForms, WinAPI or other environment. For now I’m going to give a try to WPF. I found some examples how to draw pixels on bitmap but unfortunately I have problem with understanding this code (source code from MSDN):

    // The DrawPixel method updates the WriteableBitmap by using 
    // unsafe code to write a pixel into the back buffer. 
    static void DrawPixel(MouseEventArgs e)
    {
        int column = (int)e.GetPosition(i).X;
        int row = (int)e.GetPosition(i).Y;

        // Reserve the back buffer for updates.
        writeableBitmap.Lock();

        unsafe
        {
            // Get a pointer to the back buffer. 
            int pBackBuffer = (int)writeableBitmap.BackBuffer;

            // Find the address of the pixel to draw.
            pBackBuffer += row * writeableBitmap.BackBufferStride;
            pBackBuffer += column * 4;//??

            // Compute the pixel's color. 
            int color_data = 255 << 16; // R
            color_data |= 128 << 8;   // G
            color_data |= 255 << 0;   // B 

            // Assign the color data to the pixel.
            *((int*)pBackBuffer) = color_data;//??
        }

        // Specify the area of the bitmap that changed.
        writeableBitmap.AddDirtyRect(new Int32Rect(column, row, 1, 1));

        // Release the back buffer and make it available for display.
        writeableBitmap.Unlock();
    }
  1. What is this pBackBuffer += column * 4; line for? Why 4?
  2. What does it *((int*)pBackBuffer) = color_data; mean? I know pointers from C/C++ but in C# there is IntPtr, int* and this line int pBackBuffer = (int)writeableBitmap.BackBuffer; suggests that we can treat equally int and IntPtr which is also not clear for me.
  3. Which programming environment should I use? WinAPI, WPF or other?

I would be very thankful if someone could explain me this unsafe code.

  • 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-06-12T16:35:40+00:00Added an answer on June 12, 2026 at 4:35 pm

    1: What is this pBackBuffer += column * 4; line for? Why 4?

    Assuming that pixel is ARGB, it is 4 bytes per pixel. Since column is X coordinate, it must be multiplied by 4.

    2: What does it ((int)pBackBuffer) = color_data; mean?

    (int*)pBackBuffer – treat value of int pBackBuffer as pointer to an int

    and

    *((int*)pBackBuffer) = color_data – store color_data to that pointer

    IntPtr and int are not quite the same. IntPtr is 32-bit when running on 32-bit OS and 64-bit when running on 64-bit OS. int is always 32-bit.

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

Sidebar

Related Questions

I've been looking into low level keyboard hooks lately. I have already got mine
I lately started to use htaccess to rewrite my URL's but i've got some
I've been playing around with .NET SpeechSynthesizer lately. and I've got a method that
Lately I've noticed that a lot of web programming frameworks are using a //
I got a strange problem lately with my eclipse build. When building my app
Lately we've started getting issues with outdated countries / regions list being presented to
Lately I've been job hunting, and for the most part, they would ask me
I've got a continuous integration setup using Hudson and lately I've configured the jobs
Lately, I've been cleaning up some some C code that runs on an ARM7
I've got a lovely OpenGLES code slice that renders up images for me. When

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.