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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:50:55+00:00 2026-06-13T17:50:55+00:00

I am trying to read image using native functions. To that end, i tried

  • 0

I am trying to read image using native functions. To that end, i tried using this code:

        var result = new Bitmap((int)info.width,(int)info.height,PixelFormat.Format24bppRgb);
        var data = result.LockBits(new Rectangle(0, 0, result.Width, result.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
        bool success = ReadFullImage(data.Scan0, ref info, ref png);
        result.UnlockBits(data);
        if (!success)
            return null;
        else
        {
            return result;
        }

where info contains height and width of an image, png is png_struct and ReadFullImage is wrapper around png_read_image. However, i was getting Access Violation (exception code 0xc0000005).

After that, i looked into the values data holds, i discovered this:

        data    {System.Drawing.Imaging.BitmapData} System.Drawing.Imaging.BitmapData
    Height  1557    int
        m_bmpdata   {Microsoft.AGL.Drawing.AGL_BITMAPDATA} Microsoft.AGL.Drawing.AGL_BITMAPDATA
    PixelFormat Format24bppRgb  System.Drawing.Imaging.PixelFormat
        Scan0   1638432 System.IntPtr
    Stride  1512    int
    Width   503 int

wherein seemingly lies th problem. The size of a row that is being written is 2012 bytes, yet there are only 1512 avaiable and before long there is a write attempt outside of allocated memory.

The question is, why the size of a row is only 1512=503*3+3, despite format being 24 bits per pixel, and how can sufficient memory be allocated and fed into a bitmap?

Alternatively, can png be read with libpng in the compabile way?

Update: ReadFullImage is a DllImport of

extern "C" void read_image_full( unsigned char * buffer,pngImageInfo* info,pngDataStructures* png)
{
    png_bytepp  row_pointers = new png_bytep[info->height];
    for (unsigned int i = 0;  i < info->height;  ++i)
        row_pointers[i] = buffer + i*info->rowbytes;
    png_read_image(png->png_struct_field, row_pointers);
    return true;
}

And rowbytes are retrieved via png_get_rowbytes.

  • 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-13T17:50:56+00:00Added an answer on June 13, 2026 at 5:50 pm

    First thing, as far as I know, 24/8 = 3, so 503*(24/8)=1509, then the Stride value is correct.

    The other thing is that png_read_image uses an array of pointers and Scan0 is not an array of pointers. This means that png_read_image is reading data from Scan0 (but it’s write-only) and interpreting this data as pointers.

    You can try the following (not tested). You need to modify the first parameter of ReadFullImage (now it would be an int[]):

    var result = new Bitmap((int)info.width,(int)info.height,PixelFormat.Format24bppRgb);
    var data = result.LockBits(new Rectangle(0, 0, result.Width, result.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
    int y, ptr = data.Scan0.ToInt32();
    int[] lines = new int[result.Height];
    for (y = 0; y < lines.Length; y++)
    {
        lines[y] = ptr;
        ptr += data.Stride;
    }
    bool success = ReadFullImage(lines, ref info, ref png);
    result.UnlockBits(data);
    if (!success)
        return null;
    else
    {
        return result;
    }
    

    I’m assuming this is a 32-bit application.

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

Sidebar

Related Questions

I am trying to write a code that displays an image selected using a
I'm trying to load this image using ImageIO.read() using the 1.7.0u JVM: http://taste-for-adventure.tablespoon.com/files/2012/02/2012-02-05-poll-hotdog-275w.jpg Chrome
I am trying to read a .tif image using javax.media.jai.JAI. Here is my code:
I'm trying to use the following code of java to read image data on
I am trying to read an image that resides somewhere on the web from
I'm trying to read a TIFF image from file using BufferedImage. The following is
I'm trying to read an image from the net using ImageIO: URL url =
I'm trying to read the image file stored in a MongoDB, to do that
i am trying to download a image file using ftp, on every code i
I'm trying to display a grayscale image using matplotlib.pyplot.imshow() . My problem is that

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.