how is this image stored in memory?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen.Schoenberger@gmail.com

    how is this image stored in memory?

    I am using the following code to get a monochrome bitmap image into a
    byte[] form

    Rectangle rec = new Rectangle(0, 0, bmpSource.Width ,
    bmpSource.Heigh t);
    BitmapData bmpSData = bmpSource.LockB its(rec,
    ImageLockMode.R eadWrite, bmpSource.Pixel Format);

    // Get the address of the first line.
    IntPtr iptr = bmpSData.Scan0;

    // Declare an array to hold the bytes of the bitmap.
    int ibytes = bmpSource.Width * bmpSource.Heigh t;
    byte[] bValues = new byte[ibytes];

    // Copy the values into the array.
    Marshal.Copy(ip tr, bValues, 0, ibytes); //just use this!

    how is the information stored? Meaning if I "read" bValues from 0 to
    (bmp.Width) would that get me the first line in bmpSource? And what
    would be the most effective way to save this bValues back to a Bitmap?

    Thanks
  • Fredo

    #2
    Re: how is this image stored in memory?

    Did you search Google by chance?

    Try this: http://www.codersource.net/csharp_image_Processing.aspx to get you
    started. It gives you everything you need to know about how to get at the
    pixels in BitmapData.


    <Stephen.Schoen berger@gmail.co mwrote in message
    news:f74cccb8-48b5-4197-9ad5-f6f84146e66e@q2 1g2000hsa.googl egroups.com...
    >I am using the following code to get a monochrome bitmap image into a
    byte[] form
    >
    Rectangle rec = new Rectangle(0, 0, bmpSource.Width ,
    bmpSource.Heigh t);
    BitmapData bmpSData = bmpSource.LockB its(rec,
    ImageLockMode.R eadWrite, bmpSource.Pixel Format);
    >
    // Get the address of the first line.
    IntPtr iptr = bmpSData.Scan0;
    >
    // Declare an array to hold the bytes of the bitmap.
    int ibytes = bmpSource.Width * bmpSource.Heigh t;
    byte[] bValues = new byte[ibytes];
    >
    // Copy the values into the array.
    Marshal.Copy(ip tr, bValues, 0, ibytes); //just use this!
    >
    how is the information stored? Meaning if I "read" bValues from 0 to
    (bmp.Width) would that get me the first line in bmpSource? And what
    would be the most effective way to save this bValues back to a Bitmap?
    >
    Thanks

    Comment

    • Ben Voigt [C++ MVP]

      #3
      Re: how is this image stored in memory?

      Stephen.Schoenb erger@gmail.com wrote:
      I am using the following code to get a monochrome bitmap image into a
      byte[] form
      >
      Rectangle rec = new Rectangle(0, 0, bmpSource.Width ,
      bmpSource.Heigh t);
      BitmapData bmpSData = bmpSource.LockB its(rec,
      ImageLockMode.R eadWrite, bmpSource.Pixel Format);
      Well, you asked to get the same format as the source, so to answer your
      question "it depends".

      If you want a fixed format, specify a particular PixelFormat, such as
      PixelFormat.Pix elFormat1bppInd exed or PixelFormat.Pix elFormat32bppRG B
      >
      // Get the address of the first line.
      IntPtr iptr = bmpSData.Scan0;
      >
      // Declare an array to hold the bytes of the bitmap.
      int ibytes = bmpSource.Width * bmpSource.Heigh t;
      byte[] bValues = new byte[ibytes];
      >
      // Copy the values into the array.
      Marshal.Copy(ip tr, bValues, 0, ibytes); //just use this!
      >
      how is the information stored? Meaning if I "read" bValues from 0 to
      (bmp.Width) would that get me the first line in bmpSource? And what
      would be the most effective way to save this bValues back to a Bitmap?
      >
      Thanks

      Comment

      • illusion.admins@gmail.com

        #4
        Re: how is this image stored in memory?

        On Feb 13, 7:08 pm, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
        Stephen.Schoenb er...@gmail.com wrote:
        I am using the following code to get a monochrome bitmap image into a
        byte[] form
        >
        Rectangle rec = new Rectangle(0, 0, bmpSource.Width ,
        bmpSource.Heigh t);
        BitmapData bmpSData = bmpSource.LockB its(rec,
        ImageLockMode.R eadWrite, bmpSource.Pixel Format);
        >
        Well, you asked to get the same format as the source, so to answer your
        question "it depends".
        >
        If you want a fixed format, specify a particular PixelFormat, such as
        PixelFormat.Pix elFormat1bppInd exed or PixelFormat.Pix elFormat32bppRG B
        >
        >
        >
        // Get the address of the first line.
        IntPtr iptr = bmpSData.Scan0;
        >
        // Declare an array to hold the bytes of the bitmap.
        int ibytes = bmpSource.Width * bmpSource.Heigh t;
        byte[] bValues = new byte[ibytes];
        >
        // Copy the values into the array.
        Marshal.Copy(ip tr, bValues, 0, ibytes); //just use this!
        >
        how is the information stored? Meaning if I "read" bValues from 0 to
        (bmp.Width) would that get me the first line in bmpSource? And what
        would be the most effective way to save this bValues back to a Bitmap?
        >
        Thanks
        How can I go about taking the array of bytes I have and "converting "
        it back to a Bitmap?

        Comment

        • Ben Voigt [C++ MVP]

          #5
          Re: how is this image stored in memory?

          How can I go about taking the array of bytes I have and "converting "
          it back to a Bitmap?
          Use the following Bitmap constructor:

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


          Comment

          • illusion.admins@gmail.com

            #6
            Re: how is this image stored in memory?

            On Feb 14, 11:56 am, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
            How can I go about taking the array of bytes I have and "converting "
            it back to a Bitmap?
            >
            Use the following Bitmap constructor:
            >
            public Bitmap (
            int width,
            int height,
            int stride,
            PixelFormat format,
            IntPtr scan0
            )
            Is there a way to convert the bitmap that is in a byte[] array format
            back to a bitmap?

            Comment

            • Ben Voigt [C++ MVP]

              #7
              Re: how is this image stored in memory?

              illusion.admins @gmail.com wrote:
              On Feb 14, 11:56 am, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
              >>How can I go about taking the array of bytes I have and "converting "
              >>it back to a Bitmap?
              >>
              >Use the following Bitmap constructor:
              >>
              >public Bitmap (
              > int width,
              > int height,
              > int stride,
              > PixelFormat format,
              > IntPtr scan0
              >)
              >
              Is there a way to convert the bitmap that is in a byte[] array format
              back to a bitmap?
              Did you read the post you replied to?


              Comment

              Working...