473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to convert byte array into a image?

How to convert byte array into a image?

Expand|Select|Wrap|Line Numbers
  1. Byte[] photo = Convert.FromBase64String(value);
  2.                 //System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
  3.                 //Byte[] photo = encoding.GetBytes(value);
  4.                 //old 1
  5.                 MemoryStream ms = new MemoryStream(photo, 0, photo.Length);
  6.                 ms.Position = 0;
  7.                 ms.Write(photo, 0, photo.Length);
  8.                 System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);// this line giving exception parameter not valid
  9.  
  10.                 image.Save(@"C:\MyImage2.jpg");
Nov 19 '10 #1
2 42936
Expand|Select|Wrap|Line Numbers
  1.  try
  2.             {
  3.                 //Get image data from gridview column.
  4.                 byte[] imageData = (byte[])dataGridView1.Rows[e.RowIndex].Cells["ImageData"].Value;
  5.  
  6.                 //Initialize image variable
  7.                 Image newImage;
  8.                 //Read image data into a memory stream
  9.                 using (MemoryStream ms = new MemoryStream(imageData, 0, imageData.Length))
  10.                 {
  11.                     ms.Write(imageData, 0, imageData.Length);
  12.  
  13.                     //Set image variable value using memory stream.
  14.                     newImage = Image.FromStream(ms, true);
  15.                 }
  16.  
  17.                 //set picture
  18.                 pictureBox1.Image = newImage;
  19.             }
  20.             catch(Exception ex)
  21.             {
  22.                 MessageBox.Show(ex.ToString());
  23.             }
  24.  
that code will be help you.
thanks.
Nov 29 '10 #2
wubuer
1
you can try to convert byte array pdf to jpg in c# using this control
Jul 23 '17 #3

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

Similar topics

6
by: Gator | last post by:
Hi All, Basically my situation is this, I have a server implemented in C++, unmanaged code, using proprietery protocol over TCP/IP to communicate with the cilent(c++ also). Now, I am implementing...
5
by: Andrew Inwards | last post by:
Can anyone tell me how to convert a byte array to a stream.? Thanks Andrew
4
by: Dan | last post by:
I need to convert a byte array to a string in order to upload a binary file with an httpWebRequest. What's the most efficient way to do such a conversion?
2
by: Dave | last post by:
Hi, I'm trying to convert a byte array to string --This works... System.BitConverter.ToString(bytes) "EB-55-79-20-18-B2-76-4D-85-0A-93-6B-97-33-31-B8" --This doesn't, but returns...
5
by: Terry Olsen | last post by:
Looking for info on how to convert a byte array to a string, and string to byte array. Thanks.
14
by: Charles Law | last post by:
I thought this had come up before, but I now cannot find it. I have a byte array, such as Dim a() As Byte = {1, 2, 3, 4} I want to convert this to an Int32 = 01020304 (hex). If I use...
2
by: shiplu | last post by:
I have an image which I make a byte array. Now I want to store the byte array to the database server through jsp. I have created table & query string. I am facing problem to send request to the jsp
0
by: Sergei Shelukhin | last post by:
Hi. I receive a byte array that contains utf-16 string (with a lot of \0 characters :)) from a legacy system that holds some data that is changed elsewhere. How do I convert it to an actual utf-16...
18
by: MrVS | last post by:
Hi, I have a C++ CLR class method that takes System::Byte *b as parameter argument. I want the CSharp caller pass a byte * to this function. But in the CSharp prorgram, I only managed to create a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.