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. Transferring image from webservice to PPC

Transferring image from webservice to PPC

Scheduled Pinned Locked Moved C#
graphicshelpquestion
3 Posts 2 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.
  • Y Offline
    Y Offline
    Yeast27
    wrote on last edited by
    #1

    I am trying to make a webservice that return a image to ppc. I have tried to return it as a bitmap but it give this following error "System.Drawing.Bitmap cannot be serialized because it does not have a default public constructor" so I changed from bitmap to base64 string, this works, however when I tried to convert base64 string back to bitmap(on ppc) I got the same error again.. Do anyone know exactly what I should do?

    J 1 Reply Last reply
    0
    • Y Yeast27

      I am trying to make a webservice that return a image to ppc. I have tried to return it as a bitmap but it give this following error "System.Drawing.Bitmap cannot be serialized because it does not have a default public constructor" so I changed from bitmap to base64 string, this works, however when I tried to convert base64 string back to bitmap(on ppc) I got the same error again.. Do anyone know exactly what I should do?

      J Offline
      J Offline
      John Arlen1
      wrote on last edited by
      #2

      Make sure to extract the bytes of the image to transfer. (And base64 that array) public Image GetImageFromBytes( byte[] bytes ) { MemoryStream stream = new MemoryStream(bytes); Image image = Image.FromStream( stream ); return image; } public byte[] GetImageBytes(Bitmap bitmap) { MemoryStream stream = new System.IO.MemoryStream(); bitmap.Save( stream, System.Drawing.Imaging.ImageFormat.Jpeg ); stream.Position = 0L; System.IO.BinaryReader reader = new System.IO.BinaryReader(stream); byte[] bytes = reader.ReadBytes( (int)stream.Length ); stream.Close(); return bytes; }

      Y 1 Reply Last reply
      0
      • J John Arlen1

        Make sure to extract the bytes of the image to transfer. (And base64 that array) public Image GetImageFromBytes( byte[] bytes ) { MemoryStream stream = new MemoryStream(bytes); Image image = Image.FromStream( stream ); return image; } public byte[] GetImageBytes(Bitmap bitmap) { MemoryStream stream = new System.IO.MemoryStream(); bitmap.Save( stream, System.Drawing.Imaging.ImageFormat.Jpeg ); stream.Position = 0L; System.IO.BinaryReader reader = new System.IO.BinaryReader(stream); byte[] bytes = reader.ReadBytes( (int)stream.Length ); stream.Close(); return bytes; }

        Y Offline
        Y Offline
        Yeast27
        wrote on last edited by
        #3

        public Image getObjectPicture(string objectID) { OdbcConnection connection= new OdbcConnection(@"Driver={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=ic;UID=;PASSWORD=;"); OdbcCommand cmm = new OdbcCommand("SELECT Picture FROM Object WHERE ObjectID='"+objectID+"'", connection); connection.Open(); OdbcDataReader reader = cmm.ExecuteReader(); string filename= @"c:\default.bmp"; //default pic while(reader.Read()) { filename = reader[0].ToString(); } Bitmap bitmap = new Bitmap(filename); MemoryStream stream1 = new System.IO.MemoryStream(); bitmap.Save( stream1, System.Drawing.Imaging.ImageFormat.Bmp ); stream1.Position = 0L; BinaryReader br = new BinaryReader(stream1); byte[] bytes = br.ReadBytes( (int)stream1.Length ); stream1.Close(); MemoryStream stream2 = new MemoryStream(bytes); Image image = Image.FromStream( stream2 ); return image; } I combined the given code and did this, and I got this error message "System.Drawing.Imaging.ImageFormat cannot be serialized because it does not have a default public constructor.", I put this coding on the webservice though.. that exactly should I do, I am rather confuse now

        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