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. How can I send an Image over a socket connection?

How can I send an Image over a socket connection?

Scheduled Pinned Locked Moved C#
question
3 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.
  • G Offline
    G Offline
    Gakujin
    wrote on last edited by
    #1

    I wish to know, if there is any way to send an image from one form to another using a socket conection. Say like one form can send an image to another form on a remote computer that recieves it and views it. Can it be done just using sockets? Thanks in advanced :)

    M 1 Reply Last reply
    0
    • G Gakujin

      I wish to know, if there is any way to send an image from one form to another using a socket conection. Say like one form can send an image to another form on a remote computer that recieves it and views it. Can it be done just using sockets? Thanks in advanced :)

      M Offline
      M Offline
      Michael Wolski
      wrote on last edited by
      #2

      One of the overloads for the Image.Save() method takes a System.IO.Stream. You could stream it memory, then send those bits via socket. Something like... using System.IO; using System.Net.Sockets; Bitmap bmp = new Bitmap(@"c:\mypic.gif"); System.IO.MemoryStream memImage = new MemoryStream(); bmp.Save(memImage,System.Drawing.Imaging.ImageFormat.Gif); byte[] data = memImage.ToArray(); Socket socket = new Socket(...your options here...); socket.Send(data,0,data.Length,SocketFlags.None); Hope that gets you started! Michael Developer, Author, Chef

      T 1 Reply Last reply
      0
      • M Michael Wolski

        One of the overloads for the Image.Save() method takes a System.IO.Stream. You could stream it memory, then send those bits via socket. Something like... using System.IO; using System.Net.Sockets; Bitmap bmp = new Bitmap(@"c:\mypic.gif"); System.IO.MemoryStream memImage = new MemoryStream(); bmp.Save(memImage,System.Drawing.Imaging.ImageFormat.Gif); byte[] data = memImage.ToArray(); Socket socket = new Socket(...your options here...); socket.Send(data,0,data.Length,SocketFlags.None); Hope that gets you started! Michael Developer, Author, Chef

        T Offline
        T Offline
        Tim Kohler
        wrote on last edited by
        #3

        Michael's suggestion is correct but you will also have to make sure that the client and server both send/receive the entire image. This means either putting a delimiter at the end of the image data or sending a 4 byte 'image data size' value before the image data. This is a basic socket principle so you don't not send or not receive the entire application level message.

        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