How to save more than one image in one byte array using c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anandmms
    New Member
    • Oct 2008
    • 6

    How to save more than one image in one byte array using c#

    Hello friend,

    my problem is to save more than one fingerprint images in one byte array and then store in database(oracle ).

    i dont know how to solve it. But previously i had did image saving using byte array, but i want to know how to save more than one images in one database field....

    actually i convert one image to byte array using the below code

    pb1 = picturebox1
    pb2 = picturebox2

    //Ist image

    MemoryStream ms = new MemoryStream();
    pb1.Image.Save( ms,pb1.Image.Ra wFormat);
    len = ms.Length;
    b = new byte[Convert.ToInt32 (len)];


    //IInd image

    pb2.Image.Save( ms, pb2.Image.RawFo rmat);
    len = ms.Length;
    c = new byte[Convert.ToInt32 (len)];


    how to store these two different byte array (b & c) in one byte array

    thanks in advance...

    anand
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Is this a school homework assignment?

    Comment

    • anandmms
      New Member
      • Oct 2008
      • 6

      #3
      Y r u asking like this... if u know just rpl, else keep close all of u.....

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Well the code you have, seems like BOTH images should be contained in that memorystream object, so they're both already together.
        I would recomend putting some type of deliminator between the two so you can tell them apart when you need to.

        As for why you were asked if it was homework problem, please see the Posting Guidelines about how we will not do your homework for you.

        Comment

        • Curtis Rutland
          Recognized Expert Specialist
          • Apr 2008
          • 3264

          #5
          Originally posted by anandmms
          Y r u asking like this... if u know just rpl, else keep close all of u.....
          Please read the Things that are generally unacceptable and How to ask a question entry as well.

          Use Clear English to write your question in if possible, try to avoid using abbreviations
          Do not use leet speak or text speak, they are not Clear English
          Posting in a language other than English. This is a multinational forum and as such uses English as its language as it is the international language of business. If your English is not so good then please say so and the experts will try to make some allowance for this.
          Please don't use "txt" speak like "pls" and "Y r u." Also, it's rude to our long standing members for you to tell them to give you the answer or go away.

          MODERATOR

          Comment

          • anandmms
            New Member
            • Oct 2008
            • 6

            #6
            Originally posted by Plater
            Well the code you have, seems like BOTH images should be contained in that memorystream object, so they're both already together.
            I would recomend putting some type of deliminator between the two so you can tell them apart when you need to.

            As for why you were asked if it was homework problem, please see the Posting Guidelines about how we will not do your homework for you.
            Plater, thanks for your reply... and this is not a school home work problem, but i am new to c#.net. i am facing the above problem for past several days and i cant get any proper solution... Could u post...? I need how to save more than one image in a single field(blob) in database

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              The MemoryStream can do it, you just have to be a bit more sneaky then you would think.

              [code=c#]
              //Here is the main stream
              MemoryStream fullstream = new MemoryStream();

              //dummy stream
              MemoryStream ms = new MemoryStream();
              Bitmap bm = (Bitmap)Bitmap. FromFile(@"C:\t emp.bmp");
              bm.Save(ms, ImageFormat.Bmp );

              //write one instance of the image
              ms.WriteTo(full stream);
              //write another instance of the image
              ms.WriteTo(full stream);
              //Now fullstream has 2 images in it (you can verify by the .Length property of the stream)

              //get the byte[] of two images
              byte[] superbuffer=ful lstream.ToArray ();
              [/code]

              Comment

              • anandmms
                New Member
                • Oct 2008
                • 6

                #8
                Originally posted by Plater
                The MemoryStream can do it, you just have to be a bit more sneaky then you would think.

                [code=c#]
                //Here is the main stream
                MemoryStream fullstream = new MemoryStream();

                //dummy stream
                MemoryStream ms = new MemoryStream();
                Bitmap bm = (Bitmap)Bitmap. FromFile(@"C:\t emp.bmp");
                bm.Save(ms, ImageFormat.Bmp );

                //write one instance of the image
                ms.WriteTo(full stream);
                //write another instance of the image
                ms.WriteTo(full stream);
                //Now fullstream has 2 images in it (you can verify by the .Length property of the stream)

                //get the byte[] of two images
                byte[] superbuffer=ful lstream.ToArray ();
                [/code]

                Thanks for your reply Plater,
                I checked the codes, but i am getting only one image, even writing into the memory stream(full stream) two times...

                could you please explain some more clear...

                thanks
                anand

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  Well in my example, I used the same image for each instance.
                  It was just an example.
                  You will need to provide your own method for knowing where one image ends and another image begins.

                  Comment

                  Working...