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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:40:46+00:00 2026-05-30T00:40:46+00:00

i defined my own 24 bit data type like this class _24bit{ public byte[]

  • 0

i defined my own 24 bit data type like this

class _24bit{
        public byte[] _value = new byte[3]; 
   }

i have data in binary in a _24bit data array

 _24bit  []data = new _24bit

i declared my bitmap as

Bitmap b = new Bitmap(columns / 3, rows, PixelFormat.Format24bppRgb);

but when i declare this to get a row in the bitmap

_24bit *row = (_24bit *)bmd.Scan0 + (j * bmd.Stride);

i get this compile error

Cannot take the address of, get the size of, or declare a pointer to a managed type (‘mynamespace._24bit’)

How can i proceed with my own 24bit data type ?

  • 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-30T00:40:47+00:00Added an answer on May 30, 2026 at 12:40 am

    You really can’t declare pointers to managed reference types (and your _24bit class is managed reference type). Even if you declare _24bit as a struct (making it a value type), it still contains a reference to a byte array (not byte array itself, only a reference, which makes size of this struct larger than 24 bits). You can declare you array as fixed and unsafe to fix that. You also might need to specify StructLayout attribute:

    [StructLayout(LayoutKind.Sequential, Pack=1, Size=3)]
    struct _24bpp
    {
        public unsafe fixed byte _value[3];
    }
    

    Note, that you can only access content of this struct in unsafe context. Or drop array declaration at all:

    [StructLayout(LayoutKind.Sequential, Pack=1, Size=3)]
    struct _24bpp
    {
        public byte B;
        public byte G;
        public byte R;
    }
    

    Alternatively, you can recreate bitmap in terms of your data structures and copy data from unmanaged memory to your data structures. Something like

    public static _24bit[][] GetBitmapPixelsFrom24bpp(BitmapData data)
    {
        if(data == null) throw new ArgumentNullException("data");
    
        var bitmapRows = new _24bit[rows][];
        for(int row = 0; row < data.Height; ++r)
        {
            bitmapRows[row] = new _24bit[data.Width];
            for(int pixel = 0; pixel < data.Width; ++pixel)
            {
                byte b = Marshal.ReadByte(data.Scan0, data.Stride * row + pixel * 3 + 0);
                byte g = Marshal.ReadByte(data.Scan0, data.Stride * row + pixel * 3 + 1);
                byte r = Marshal.ReadByte(data.Scan0, data.Stride * row + pixel * 3 + 2);
                var bitmapPixel = new _24bit();
                bitmapPixel._value[0] = b;
                bitmapPixel._value[1] = g;
                bitmapPixel._value[2] = r;
                bitmapRows[row][pixel] = bitmapPixel;
            }
        }
        return bitmapRows;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that defines its own enum like this: public class Test
I have a GADT that's a lot like this: data In a where M
I'm programming using GWT, which includes Jetty. I have defined my own servlet and
Well i have a gridview where i have defined the columns on my own
I have found some info on the subject ( like this link) , but
I would like to write my own model binder for DateTime type. First of
How do I use the JQuery delay in conjunction with my own defined function,
The question is a bit hypothetical. Let's say I have an application that draws
I have a C++ class Finder that stores a location in containers plus some
I'm a bit new to Python dev -- I'm creating a larger project for

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.