Transferring image from webservice to PPC
-
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?
-
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?
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; }
-
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; }
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