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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. convert image to Byte

convert image to Byte

Scheduled Pinned Locked Moved C#
tutorialquestion
7 Posts 5 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.
  • T Offline
    T Offline
    TAREQ F ABUZUHRI
    wrote on last edited by
    #1

    Image img; DataPhoto = new Byte[File.ContentLength]; img=Image.FromStream(DataPhoto); the above code convert Byte to Image my quastion how to convert image to Byte ???

    Palestine

    P 1 Reply Last reply
    0
    • T TAREQ F ABUZUHRI

      Image img; DataPhoto = new Byte[File.ContentLength]; img=Image.FromStream(DataPhoto); the above code convert Byte to Image my quastion how to convert image to Byte ???

      Palestine

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      Create a MemoryStream object and use the Image.Save to save the image data to the MemoryStream. Then read the contents of the MemoryStream into a byte array by calling its ToArray method. Paul

      T 1 Reply Last reply
      0
      • P pmarfleet

        Create a MemoryStream object and use the Image.Save to save the image data to the MemoryStream. Then read the contents of the MemoryStream into a byte array by calling its ToArray method. Paul

        T Offline
        T Offline
        TAREQ F ABUZUHRI
        wrote on last edited by
        #3

        can u give me example ?

        Palestine

        S L 2 Replies Last reply
        0
        • T TAREQ F ABUZUHRI

          can u give me example ?

          Palestine

          S Offline
          S Offline
          Steve Hansen
          wrote on last edited by
          #4

          MemoryStream ms = new MemoryStream(); img.Save(ms); byte[] bytes = ms.ToArray();

          1 Reply Last reply
          0
          • T TAREQ F ABUZUHRI

            can u give me example ?

            Palestine

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

            If you close the MemoryStream as per the other user's example code, you might get the same GDI+ exception. Best is to use it in a 'using' construct.

            **

            xacc.ide-0.2.0.77 - now with C# 3.5 support and Navigation Bar!^
            New xacc.ide release RSS feed^

            **

            T 1 Reply Last reply
            0
            • L leppie

              If you close the MemoryStream as per the other user's example code, you might get the same GDI+ exception. Best is to use it in a 'using' construct.

              **

              xacc.ide-0.2.0.77 - now with C# 3.5 support and Navigation Bar!^
              New xacc.ide release RSS feed^

              **

              T Offline
              T Offline
              TAREQ F ABUZUHRI
              wrote on last edited by
              #6

              please need example to know what u mean exactly ..

              Palestine

              M 1 Reply Last reply
              0
              • T TAREQ F ABUZUHRI

                please need example to know what u mean exactly ..

                Palestine

                M Offline
                M Offline
                Mairaaj Khan
                wrote on last edited by
                #7

                Normally, CLR (Common Language Runtime) manages garbage collections. But in certain situation there is a need to release the resources used by the object(s) as soon as possible. For this purpose, using statement can be used. According to MSDN: The using statement allows the programmer to specify when objects that use resources should release them. The object provided to the using statement must implement the **IDisposable** interface. This interface provides the **Dispose** method, which should release the object's resources. A using statement can be exited either when the end of the using statement is reached or if an exception is thrown and control leaves the statement block before the end of the statement. For the examples, see msdn[^] Regards.

                ________________________________ Success is not something to wait for, its something to work for.

                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