Assembling bytes to an image
-
Hi all. I have a client-server distributed system. I want to transfer and image from the server to the client. In the server i have converted a .bmp image to byte array as this:
Image imageIn = Image.FromFile("me.bmp") ; MemoryStream msr = new MemoryStream(); imageIn.Save(msr, System.Drawing.Imaging.ImageFormat.Gif); byte\[\] byteIm = msr.ToArray(); ms.Send(byteIm);
The bytes are being transfered okay to the client. The problem is that i don't know how to assemble this byte back to an image to show in a picture box. That is:
pictureBox1.Image =
:confused:
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
-
Hi all. I have a client-server distributed system. I want to transfer and image from the server to the client. In the server i have converted a .bmp image to byte array as this:
Image imageIn = Image.FromFile("me.bmp") ; MemoryStream msr = new MemoryStream(); imageIn.Save(msr, System.Drawing.Imaging.ImageFormat.Gif); byte\[\] byteIm = msr.ToArray(); ms.Send(byteIm);
The bytes are being transfered okay to the client. The problem is that i don't know how to assemble this byte back to an image to show in a picture box. That is:
pictureBox1.Image =
:confused:
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
-
Hi all. I have a client-server distributed system. I want to transfer and image from the server to the client. In the server i have converted a .bmp image to byte array as this:
Image imageIn = Image.FromFile("me.bmp") ; MemoryStream msr = new MemoryStream(); imageIn.Save(msr, System.Drawing.Imaging.ImageFormat.Gif); byte\[\] byteIm = msr.ToArray(); ms.Send(byteIm);
The bytes are being transfered okay to the client. The problem is that i don't know how to assemble this byte back to an image to show in a picture box. That is:
pictureBox1.Image =
:confused:
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
-
Actually that is where i knew how to convert and image to bytes but the function returning an Image, how will the pictureBox get the URL?
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
-
Here you go:
MemoryStream memStream = new MemoryStream(imageBytes);
Image image = Image.FromStream(memStream); -
Actually that is where i knew how to convert and image to bytes but the function returning an Image, how will the pictureBox get the URL?
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
Why would the picture box want a URL? Just give it the image, or save it to disk and then give it the url as the file location. From your original code:
MemoryStream ms = new MemoryStream(byteArrayIn); pictureBox1.Image = Image.FromStream(ms);
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
Hi all. I have a client-server distributed system. I want to transfer and image from the server to the client. In the server i have converted a .bmp image to byte array as this:
Image imageIn = Image.FromFile("me.bmp") ; MemoryStream msr = new MemoryStream(); imageIn.Save(msr, System.Drawing.Imaging.ImageFormat.Gif); byte\[\] byteIm = msr.ToArray(); ms.Send(byteIm);
The bytes are being transfered okay to the client. The problem is that i don't know how to assemble this byte back to an image to show in a picture box. That is:
pictureBox1.Image =
:confused:
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
try following code: private void Button2_Click(object sender, System.EventArgs e) { connection.Open(); SqlCommand command1 = new SqlCommand("select imgfile from myimages where imgname=@param", connection); SqlParameter myparam = command1.Parameters.Add("@param", SqlDbType.NVarChar, 30); myparam.Value = txtimgname.Text; byte[] img = (byte[])command1.ExecuteScalar(); MemoryStream str = new MemoryStream(); str.Write(img, 0, img.Length); Bitmap bit = new Bitmap(str); Response.ContentType = "image/jpeg";//or you can select your imagetype from database or directly write it here bit.Save(Response.OutputStream, ImageFormat.Jpeg); connection.Close(); } change your database name, field name, image name, attribute name. If You Get your answer then please Rating me... Thanks.. "Are You Ready" DX-ARMY