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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:52:08+00:00 2026-05-27T16:52:08+00:00

I have a 8 bit bitmap color image. when i do a Color pixelcolor

  • 0

I have a 8 bit bitmap color image. when i do a

Color pixelcolor = b.GetPixel(j,i);    
Console.Write(pixelcolor.ToString() + " " );

I get

 Color [A=255, R=255, G=255, B=255]

I need to get only the 8 bit value. not 24 bit seperate values for R,G,B ,A.

  • 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-27T16:52:09+00:00Added an answer on May 27, 2026 at 4:52 pm

    There is no way to do this using the Bitmap class directly. However, you can use the LockBits method to access the pixels directly.

    Using unsafe code: (remember to enable unsafe code in your project first)

    public static unsafe Byte GetIndexedPixel(Bitmap b, Int32 x, Int32 y)
    {
        if (b.PixelFormat != PixelFormat.Format8bppIndexed) throw new ArgumentException("Image is not in 8 bit per pixel indexed format!");
        if (x < 0 || x >= b.Width) throw new ArgumentOutOfRangeException("x", string.Format("x should be in 0-{0}", b.Width));
        if (y < 0 || y >= b.Height) throw new ArgumentOutOfRangeException("y", string.Format("y should be in 0-{0}", b.Height));
        BitmapData data = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, b.PixelFormat);
        try
        {
            Byte* scan0 = (Byte*)data.Scan0;
            return scan0[x + y * data.Stride];
        }
        finally
        {
            if (data != null) b.UnlockBits(data);
        }
    }
    

    The safe alternative, using Marshal.Copy:

    public static Byte GetIndexedPixel(Bitmap b, Int32 x, Int32 y)
    {
        if (b.PixelFormat != PixelFormat.Format8bppIndexed) throw new ArgumentException("Image is not in 8 bit per pixel indexed format!");
        if (x < 0 || x >= b.Width) throw new ArgumentOutOfRangeException("x", string.Format("x should be in 0-{0}", b.Width));
        if (y < 0 || y >= b.Height) throw new ArgumentOutOfRangeException("y", string.Format("y should be in 0-{0}", b.Height));
        BitmapData data = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, b.PixelFormat);
        try
        {
            Byte[] pixel = new Byte[1];
            Marshal.Copy(new IntPtr(data.Scan0.ToInt64() + x + y * data.Stride), pixel, 0, 1);
            return pixel[0];
        }
        finally
        {
            if (data != null) b.UnlockBits(data);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 24-bit bitmaps with R, G, B color channels and a 24-bit
In ASP.NET C# I'm trying to save a bitmap image as an 16-color non-transparent
I have a bit of a weird problem here! I am trying to write
i have a 1D array. I copied the data onto a 8 bit color
I have a bitmap and I draw it like this : bit = BitmapFactory.decodeResource(getResources(),
Suppose I already have a bitmap (an image) in Device (Video) Memory using cudaMalloc()
I am a bit confused. I have an ARGB bitmap into an unsigned char*
For a mobile application I have to generate a 1-bit-bitmap out of a 24-bit-bitmap.
i have bit of code that causes an underflow: var t1, t2, delta: DWORD:
I have this bit of javascript written with jQuery 1.2.5. It's contained inside 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.