Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Cannot seem to be able to write a byte[] to a file

Cannot seem to be able to write a byte[] to a file

Scheduled Pinned Locked Moved C#
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LCI
    wrote on last edited by
    #1

    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(); }

    G L 2 Replies Last reply
    0
    • L LCI

      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(); }

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      Why don't you use BinaryWriter instead?

      Giorgi Dalakishvili #region signature my articles #endregion

      1 Reply Last reply
      0
      • L LCI

        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(); }

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        System.IO.File.WriteAllBytes()

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 4a out now (29 May 2008)

        L 1 Reply Last reply
        0
        • L leppie

          System.IO.File.WriteAllBytes()

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          L Offline
          L Offline
          LCI
          wrote on last edited by
          #4

          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?

          L 1 Reply Last reply
          0
          • L LCI

            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?

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            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)

            L 1 Reply Last reply
            0
            • L leppie

              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)

              L Offline
              L Offline
              LCI
              wrote on last edited by
              #6

              thanks, i'll try that. If i would like to put 4 images on the form, i would have to write them to a control write?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups