convert image to byte array and the other way?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • piggy

    convert image to byte array and the other way?

    I am trying to convert an image to an byte array (tobytes() method) and from
    byte array back to an image (frombytes() method). The problem i have here is
    say the image size is 285 bytes but the total bytes is 635. I know it would
    include the header but the header should be the same size regardless of the
    image size. I tested the other image size of 407 bytes and the total bytes
    array is 727. I am not sure what is wrong? your help would be appreciate
    it.
  • Stoitcho Goutsev \(100\)

    #2
    Re: convert image to byte array and the other way?

    What is the image size and total size? How do you calculate the image size?


    --
    Stoitcho Goutsev (100)

    "piggy" <piggy@discussi ons.microsoft.c omwrote in message
    news:6FED606A-BD1F-4F8C-B6F2-DF387B703CAD@mi crosoft.com...
    >I am trying to convert an image to an byte array (tobytes() method) and
    >from
    byte array back to an image (frombytes() method). The problem i have here
    is
    say the image size is 285 bytes but the total bytes is 635. I know it
    would
    include the header but the header should be the same size regardless of
    the
    image size. I tested the other image size of 407 bytes and the total
    bytes
    array is 727. I am not sure what is wrong? your help would be appreciate
    it.

    Comment

    • Ignacio Machin \( .NET/ C# MVP \)

      #3
      Re: convert image to byte array and the other way?

      Hi,

      What is the problem with a variable size?

      Just handle the entire array as one entity.

      You can you use a MemoryStream to convert to/from byte


      --
      --
      Ignacio Machin,
      ignacio.machin AT dot.state.fl.us
      Florida Department Of Transportation


      "piggy" <piggy@discussi ons.microsoft.c omwrote in message
      news:6FED606A-BD1F-4F8C-B6F2-DF387B703CAD@mi crosoft.com...
      >I am trying to convert an image to an byte array (tobytes() method) and
      >from
      byte array back to an image (frombytes() method). The problem i have here
      is
      say the image size is 285 bytes but the total bytes is 635. I know it
      would
      include the header but the header should be the same size regardless of
      the
      image size. I tested the other image size of 407 bytes and the total
      bytes
      array is 727. I am not sure what is wrong? your help would be appreciate
      it.

      Comment

      • JustinC

        #4
        Re: convert image to byte array and the other way?

        If you have an image, you can have a file. If you have a file you have
        a filestream. If you have a filestream you can get an array of bytes.
        You might have to mess around with what streams you need, probably a
        mix of FileStream and MemoryStream.

        Ignacio Machin ( .NET/ C# MVP ) wrote:
        Hi,
        >
        What is the problem with a variable size?
        >
        Just handle the entire array as one entity.
        >
        You can you use a MemoryStream to convert to/from byte
        >
        >
        --
        --
        Ignacio Machin,
        ignacio.machin AT dot.state.fl.us
        Florida Department Of Transportation
        >
        >
        "piggy" <piggy@discussi ons.microsoft.c omwrote in message
        news:6FED606A-BD1F-4F8C-B6F2-DF387B703CAD@mi crosoft.com...
        I am trying to convert an image to an byte array (tobytes() method) and
        from
        byte array back to an image (frombytes() method). The problem i have here
        is
        say the image size is 285 bytes but the total bytes is 635. I know it
        would
        include the header but the header should be the same size regardless of
        the
        image size. I tested the other image size of 407 bytes and the total
        bytes
        array is 727. I am not sure what is wrong? your help would be appreciate
        it.

        Comment

        • Tom Spink

          #5
          Re: convert image to byte array and the other way?

          piggy wrote:
          I am trying to convert an image to an byte array (tobytes() method) and
          from
          byte array back to an image (frombytes() method). The problem i have here
          is
          say the image size is 285 bytes but the total bytes is 635. I know it
          would include the header but the header should be the same size regardless
          of the
          image size. I tested the other image size of 407 bytes and the total
          bytes
          array is 727. I am not sure what is wrong? your help would be appreciate
          it.
          Hi Piggy,

          Can you post some code, demonstrating what you are doing, and how you are
          obtaining 'image size' and 'total bytes'?

          --
          Hope this helps,
          Tom Spink

          Google first, ask later.

          Comment

          • Peter Bromberg [C# MVP]

            #6
            RE: convert image to byte array and the other way?

            Your Image Class sports a Save and a FromStream method, both of which can
            work with a stream such as a MemoryStream. MemoryStream class has a
            contructor overload that accepts a byte array, and it has a ToArray method
            that gives you back a byte array. The header (Jpeg, gif, etc is simply part
            of this array and you should not need to worry about it at all.
            Hope that helps,
            Peter

            --
            Co-founder, Eggheadcafe.com developer portal:

            UnBlog:





            "piggy" wrote:
            I am trying to convert an image to an byte array (tobytes() method) and from
            byte array back to an image (frombytes() method). The problem i have here is
            say the image size is 285 bytes but the total bytes is 635. I know it would
            include the header but the header should be the same size regardless of the
            image size. I tested the other image size of 407 bytes and the total bytes
            array is 727. I am not sure what is wrong? your help would be appreciate
            it.

            Comment

            • piggy

              #7
              RE: convert image to byte array and the other way?

              The problem is that we try to send as small as package size over the network
              as possible. I am just curious. If that is how it works and there are no
              ways to fix it then have to accept it. Thanks for your comments.

              "Peter Bromberg [C# MVP]" wrote:
              Your Image Class sports a Save and a FromStream method, both of which can
              work with a stream such as a MemoryStream. MemoryStream class has a
              contructor overload that accepts a byte array, and it has a ToArray method
              that gives you back a byte array. The header (Jpeg, gif, etc is simply part
              of this array and you should not need to worry about it at all.
              Hope that helps,
              Peter
              >
              --
              Co-founder, Eggheadcafe.com developer portal:

              UnBlog:

              >
              >
              >
              >
              "piggy" wrote:
              >
              I am trying to convert an image to an byte array (tobytes() method) and from
              byte array back to an image (frombytes() method). The problem i have here is
              say the image size is 285 bytes but the total bytes is 635. I know it would
              include the header but the header should be the same size regardless of the
              image size. I tested the other image size of 407 bytes and the total bytes
              array is 727. I am not sure what is wrong? your help would be appreciate
              it.

              Comment

              • piggy

                #8
                Re: convert image to byte array and the other way?

                i don't calculate the image size. I just check the image size from window
                explorer. Is there a way to do it?

                "Stoitcho Goutsev (100)" wrote:
                What is the image size and total size? How do you calculate the image size?
                >
                >
                --
                Stoitcho Goutsev (100)
                >
                "piggy" <piggy@discussi ons.microsoft.c omwrote in message
                news:6FED606A-BD1F-4F8C-B6F2-DF387B703CAD@mi crosoft.com...
                I am trying to convert an image to an byte array (tobytes() method) and
                from
                byte array back to an image (frombytes() method). The problem i have here
                is
                say the image size is 285 bytes but the total bytes is 635. I know it
                would
                include the header but the header should be the same size regardless of
                the
                image size. I tested the other image size of 407 bytes and the total
                bytes
                array is 727. I am not sure what is wrong? your help would be appreciate
                it.
                >
                >
                >

                Comment

                • piggy

                  #9
                  RE: convert image to byte array and the other way?

                  I agree that header is a part of the array but shoudn't it be the same size
                  regarless of the image size? It will be different depending on the image
                  type as well.

                  "piggy" wrote:
                  The problem is that we try to send as small as package size over the network
                  as possible. I am just curious. If that is how it works and there are no
                  ways to fix it then have to accept it. Thanks for your comments.
                  >
                  "Peter Bromberg [C# MVP]" wrote:
                  >
                  Your Image Class sports a Save and a FromStream method, both of which can
                  work with a stream such as a MemoryStream. MemoryStream class has a
                  contructor overload that accepts a byte array, and it has a ToArray method
                  that gives you back a byte array. The header (Jpeg, gif, etc is simply part
                  of this array and you should not need to worry about it at all.
                  Hope that helps,
                  Peter

                  --
                  Co-founder, Eggheadcafe.com developer portal:

                  UnBlog:





                  "piggy" wrote:
                  I am trying to convert an image to an byte array (tobytes() method) and from
                  byte array back to an image (frombytes() method). The problem i have here is
                  say the image size is 285 bytes but the total bytes is 635. I know it would
                  include the header but the header should be the same size regardless of the
                  image size. I tested the other image size of 407 bytes and the total bytes
                  array is 727. I am not sure what is wrong? your help would be appreciate
                  it.

                  Comment

                  Working...