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. Memory stream

Memory stream

Scheduled Pinned Locked Moved C#
graphicsperformancehelp
5 Posts 3 Posters 1 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.
  • S Offline
    S Offline
    sirisha guttikonda
    wrote on last edited by
    #1

    Hi all .. I'm trying to save an image from memory stream content. but getting error like "Parameter is not valid." at newImage = System.Drawing.Image.FromStream(ms); can you please suggest me. Here is my code..

    System.Drawing.Image newImage;

    using (MemoryStream ms = new MemoryStream(photoByte, 0, photoByte.Length))
    {

                        ms.Write(photoByte, 0, photoByte.Length);
                        
                        newImage = System.Drawing.Image.FromStream(ms);
    
                       
                        newImage.Save(strFileName);
    
                        img.Attributes.Add("src", strFileName);
                    }
    

    Thanks

    siri

    G N 2 Replies Last reply
    0
    • S sirisha guttikonda

      Hi all .. I'm trying to save an image from memory stream content. but getting error like "Parameter is not valid." at newImage = System.Drawing.Image.FromStream(ms); can you please suggest me. Here is my code..

      System.Drawing.Image newImage;

      using (MemoryStream ms = new MemoryStream(photoByte, 0, photoByte.Length))
      {

                          ms.Write(photoByte, 0, photoByte.Length);
                          
                          newImage = System.Drawing.Image.FromStream(ms);
      
                         
                          newImage.Save(strFileName);
      
                          img.Attributes.Add("src", strFileName);
                      }
      

      Thanks

      siri

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      After writing to the stream you have to reset the position to the beginning of the stream before reading it.

      Despite everything, the person most likely to be fooling you next is yourself.

      S 1 Reply Last reply
      0
      • G Guffa

        After writing to the stream you have to reset the position to the beginning of the stream before reading it.

        Despite everything, the person most likely to be fooling you next is yourself.

        S Offline
        S Offline
        sirisha guttikonda
        wrote on last edited by
        #3

        Thanks for your reply.. but.. still i'm getting same error Thanks

        siri

        1 Reply Last reply
        0
        • S sirisha guttikonda

          Hi all .. I'm trying to save an image from memory stream content. but getting error like "Parameter is not valid." at newImage = System.Drawing.Image.FromStream(ms); can you please suggest me. Here is my code..

          System.Drawing.Image newImage;

          using (MemoryStream ms = new MemoryStream(photoByte, 0, photoByte.Length))
          {

                              ms.Write(photoByte, 0, photoByte.Length);
                              
                              newImage = System.Drawing.Image.FromStream(ms);
          
                             
                              newImage.Save(strFileName);
          
                              img.Attributes.Add("src", strFileName);
                          }
          

          Thanks

          siri

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          sirisha guttikonda wrote:

          new MemoryStream(photoByte, 0, photoByte.Length)

          sirisha guttikonda wrote:

          ms.Write(photoByte, 0, photoByte.Length);

          When you call new MemoryStream(photoByte, 0, photoByte.Length), the contents in the photoByte will be written to the stream. So calling the Write() again is pointless. Here is a code which worked at my end

          using(MemoryStream stream = new MemoryStream(photoByte,0,photoByte.Length))
          using (Image image = Image.FromStream(stream))
          {
          image.Save(@"filename.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
          }

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

          S 1 Reply Last reply
          0
          • N N a v a n e e t h

            sirisha guttikonda wrote:

            new MemoryStream(photoByte, 0, photoByte.Length)

            sirisha guttikonda wrote:

            ms.Write(photoByte, 0, photoByte.Length);

            When you call new MemoryStream(photoByte, 0, photoByte.Length), the contents in the photoByte will be written to the stream. So calling the Write() again is pointless. Here is a code which worked at my end

            using(MemoryStream stream = new MemoryStream(photoByte,0,photoByte.Length))
            using (Image image = Image.FromStream(stream))
            {
            image.Save(@"filename.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

            S Offline
            S Offline
            sirisha guttikonda
            wrote on last edited by
            #5

            Thank You...

            siri

            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