469,591 Members | 2,136 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,591 developers. It's quick & easy.

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.RawFormat);
len = ms.Length;
b = new byte[Convert.ToInt32(len)];


//IInd image

pb2.Image.Save(ms, pb2.Image.RawFormat);
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
Oct 11 '08 #1
8 8871
tlhintoq
3,525 Expert 2GB
Is this a school homework assignment?
Oct 12 '08 #2
Y r u asking like this... if u know just rpl, else keep close all of u.....
Oct 13 '08 #3
Plater
7,872 Expert 4TB
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.
Oct 13 '08 #4
Curtis Rutland
3,256 Expert 2GB
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
Oct 13 '08 #5
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
Oct 15 '08 #6
Plater
7,872 Expert 4TB
The MemoryStream can do it, you just have to be a bit more sneaky then you would think.

Expand|Select|Wrap|Line Numbers
  1. //Here is the main stream
  2. MemoryStream fullstream = new MemoryStream();
  3.  
  4. //dummy stream
  5. MemoryStream ms = new MemoryStream();
  6. Bitmap bm = (Bitmap)Bitmap.FromFile(@"C:\temp.bmp");
  7. bm.Save(ms, ImageFormat.Bmp);    
  8.  
  9. //write one instance of the image
  10. ms.WriteTo(fullstream);
  11. //write another instance of the image
  12. ms.WriteTo(fullstream);
  13. //Now fullstream has 2 images in it (you can verify by the .Length property of the stream)
  14.  
  15. //get the byte[] of two images
  16. byte[] superbuffer=fullstream.ToArray();
  17.  
Oct 15 '08 #7
The MemoryStream can do it, you just have to be a bit more sneaky then you would think.

Expand|Select|Wrap|Line Numbers
  1. //Here is the main stream
  2. MemoryStream fullstream = new MemoryStream();
  3.  
  4. //dummy stream
  5. MemoryStream ms = new MemoryStream();
  6. Bitmap bm = (Bitmap)Bitmap.FromFile(@"C:\temp.bmp");
  7. bm.Save(ms, ImageFormat.Bmp);    
  8.  
  9. //write one instance of the image
  10. ms.WriteTo(fullstream);
  11. //write another instance of the image
  12. ms.WriteTo(fullstream);
  13. //Now fullstream has 2 images in it (you can verify by the .Length property of the stream)
  14.  
  15. //get the byte[] of two images
  16. byte[] superbuffer=fullstream.ToArray();
  17.  

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
Oct 18 '08 #8
Plater
7,872 Expert 4TB
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.
Oct 20 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Mark Johnson | last post: by
9 posts views Thread by Ivan Demkovitch | last post: by
1 post views Thread by Markusek Peter | last post: by
15 posts views Thread by Sharon | last post: by
3 posts views Thread by =?Utf-8?B?Um9nZWxpbw==?= | last post: by
4 posts views Thread by Logician | last post: by
6 posts views Thread by Jerry Spence1 | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.