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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:49:46+00:00 2026-06-09T20:49:46+00:00

I have an array like byte[] pixels . Is there any way to create

  • 0

I have an array like byte[] pixels. Is there any way to create a bitmap object from that pixels without copying data? I have a small graphics library, when I need to display image on WinForms window I just copy that data to a bitmap object, then I use draw method. Can I avoid this copying process? I remember I saw it somewhere, but maybe my memory is just bad.

Edit: I tried this code and it works, but is this safe?

byte[] pixels = new byte[10 * 10 * 4];

pixels[4] = 255; // set 1 pixel
pixels[5] = 255;
pixels[6] = 255;
pixels[7] = 255;

// do some tricks
GCHandle pinnedArray = GCHandle.Alloc(pixels, GCHandleType.Pinned);
IntPtr pointer = pinnedArray.AddrOfPinnedObject();

// create a new bitmap.
Bitmap bmp = new Bitmap (10, 10, 4*10, PixelFormat.Format32bppRgb, pointer);

Graphics grp = this.CreateGraphics ();
grp.DrawImage (bmp, 0, 0);

pixels[4+12] = 255; // add a pixel
pixels[5+12] = 255;
pixels[6+12] = 255;
pixels[7+12] = 255;

grp.DrawImage (bmp, 0, 40);
  • 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-09T20:49:47+00:00Added an answer on June 9, 2026 at 8:49 pm

    There is a constructor that takes a pointer to raw image data:

    Bitmap Constructor (Int32, Int32, Int32, PixelFormat, IntPtr)

    Example:

    byte[] _data = new byte[]
    {
        255, 0, 0, 255, // Blue
        0, 255, 0, 255, // Green
        0, 0, 255, 255, // Red
        0, 0, 0, 255,   // Black
    };
    
    var arrayHandle = System.Runtime.InteropServices.GCHandle.Alloc(_data,
            System.Runtime.InteropServices.GCHandleType.Pinned);
    
    var bmp = new Bitmap(2, 2, // 2x2 pixels
        8,                     // RGB32 => 8 bytes stride
        System.Drawing.Imaging.PixelFormat.Format32bppArgb,
        arrayHandle.AddrOfPinnedObject()
    );
    
    this.BackgroundImageLayout = ImageLayout.Stretch;
    this.BackgroundImage = bmp;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SHA-1 byte array that I would like to use in a
I have to create BYTE* array that will store some text and binary data
I have a byte array in memory, read from a file. I would like
I have byte array as input. I would like to convert that array to
I have a NSData object which is supposed to work like a byte array.
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
I've got an object[] array which contains some mixture of builtin types, like Int/Byte/String,
I have an array of bytes that I would like to store as a
I have a byte array like this: lzo_bytep out; // my byte array size_t
I have a static array like below static byte[] myArray = {0x01,0x02}; I read

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.