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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:27:06+00:00 2026-06-08T19:27:06+00:00

I have an image width/height/stride and buffer. How do I convert this information to

  • 0

I have an image width/height/stride and buffer.

How do I convert this information to a System.Drawing.Bitmap? Can I get the original image back if I have these 4 things?

  • 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-08T19:27:09+00:00Added an answer on June 8, 2026 at 7:27 pm

    There is a Bitmap constructor overload, which requires everything you have (plus PixelFormat):

    public Bitmap(int width, int height, int stride, PixelFormat format, IntPtr scan0);

    This might work (if args.Buffer is an array of blittable type, like byte for example):

    Bitmap bitmap;
    var gch = System.Runtime.InteropServices.GCHandle.Alloc(args.Buffer, GCHandleType.Pinned);
    try
    {
        bitmap = new Bitmap(
            args.Width, args.Height, args.Stride,
            System.Drawing.Imaging.PixelFormat.Format24bppRgb,
            gch.AddrOfPinnedObject());
    }
    finally
    {
        gch.Free();
    }
    

    Update:

    Probably it’s better to copy image bytes to newly created Bitmap manually, because it seems like that constructors doesn’t do that, and if byte[] array of image data gets garbage collected all sorts of bad things can happen.

    var bitmap = new Bitmap(args.Width, args.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
    var data = bitmap.LockBits(
        new Rectangle(0, 0, args.Width, args.Height),
        System.Drawing.Imaging.ImageLockMode.WriteOnly,
        System.Drawing.Imaging.PixelFormat.Format24bppRgb);
    
    if(data.Stride == args.Stride)
    {
        Marshal.Copy(args.Buffer, 0, data.Scan0, args.Stride * args.Height);
    }
    else
    {
        int arrayOffset = 0;
        int imageOffset = 0;
        for(int y = 0; y < args.Height; ++y)
        {
            Marshal.Copy(args.Buffer, arrayOffset, (IntPtr)(((long)data.Scan0) + imageOffset), data.Stride);
            arrayOffset += args.Stride;
            imageOffset += data.Stride;
        }
    }
    
    bitmap.UnlockBits(data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anyway to get image width and height without downloading from original location
How to get width and height of an image? I have $variable = 'http://site.com/image.png
I have an image with height 173px and width 157px .I want to set
I have custom map image with specific height and width. i need to map
I have the following code a.rollover { background-image: url('sprite.jpg'); display: block; width: 191px; height:
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
import Image image = Image.open('images/original.jpg') width = image.size[0] height = image.size[1] if width >
I have stored an Image to Database. I can get the blob but unable
I have an image with width/height from the CSS file. I have now added
I have a method to copy the data out of a System.Drawing.Bitmap which looks

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.