Cannot seem to be able to write a byte[] to a file
-
I am using StreamWriter to write out some jpeg data in byte[] to a file. The result of my file is always "System.Byte[]" byte[] jpegData = new byte[img.Length]; jpegData = Convert.FromBase64String(img); using (StreamWriter sr1 = new StreamWriter("C:\\123.jpg")) { sr1.Write(Convert.ToString(jpegData)); sr1.Flush(); sr1.Close(); }
-
I am using StreamWriter to write out some jpeg data in byte[] to a file. The result of my file is always "System.Byte[]" byte[] jpegData = new byte[img.Length]; jpegData = Convert.FromBase64String(img); using (StreamWriter sr1 = new StreamWriter("C:\\123.jpg")) { sr1.Write(Convert.ToString(jpegData)); sr1.Flush(); sr1.Close(); }
Why don't you use BinaryWriter instead?
Giorgi Dalakishvili #region signature my articles #endregion
-
I am using StreamWriter to write out some jpeg data in byte[] to a file. The result of my file is always "System.Byte[]" byte[] jpegData = new byte[img.Length]; jpegData = Convert.FromBase64String(img); using (StreamWriter sr1 = new StreamWriter("C:\\123.jpg")) { sr1.Write(Convert.ToString(jpegData)); sr1.Flush(); sr1.Close(); }
-
System.IO.File.WriteAllBytes()
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
Thanks, this worked great. Do you know how i would write this jpeg data in the form of byte[] to a form instead of to a file? So in other words i would like to display jpg on the form. Would i need a picture control?
-
You can simply do:
myform.BackgroundImage = Image.FromStream(new MemoryStream(jpegbytes));
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)