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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:36:50+00:00 2026-05-20T06:36:50+00:00

I am writing an imaging app in WPF C#. It reads the image file

  • 0

I am writing an imaging app in WPF C#. It reads the image file pixel by pixel using unsafe code.

The problem I am getting is it throws the error Attempted to read or write protected memory. This is often an indication that other memory is corrupt. when writing the pixel value. It works fine for some images and for others it shows the error. Following is the code:

unsafe
            {
                byte* pbuff = (byte*)buff.ToPointer();
                for (int i = 0; i < size; i=i+stride)
                  {
                        pbuff[i] = (byte)cr[j].NewColor.Blue;
                        pbuff[i + 1] = (byte)cr[j].NewColor.Green; // here it shows error
                        pbuff[i + 2] = (byte)cr[j].NewColor.Red;
                   }
            }

EDIT

Reading of the pixels works fine.

                B = (double)pbuff[i];
                G = (double)pbuff[i + 1];
                R = (double)pbuff[i + 2];

It does not shows any error while reading but for the same index (that was read) it shows error when attempted to write.

  • 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-20T06:36:51+00:00Added an answer on May 20, 2026 at 6:36 am

    Basically this means that you are trying to write to the memory outside the memory allocated for the object referenced by pbuff.

    So this is basically the same as array index out of bounds in safe code.

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

Sidebar

Related Questions

Writing a python program, and I came up with this error while using the
For the iPad imaging app I am writing I have include the ability to
I am writing an imaging library (using the MIT licence) and would like to
I'm writing an iPhone app which fetches an XML file, parses it and then
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
Writing documentation in html requires some code examples. What to do with characters that
Writing an asynchronous Ping using Raw Sockets in F#, to enable parallel requests using
While writing some C code, I decided to compile it to assembly and read
Hi I'm trying to install the python image library at www.pythonware.com/products/pil and am getting
I'm writing an app which for various reasons involves Internet Explorer (IE7, for 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.