c# - ImageConverter: Parameter is not valid for a byte array -
I am sending string formatted data from an iPhone client code to a web service. I am trying to encode it in binary 64 and then converting it into a byte array. I get the problem of parameter not valid
at the following point in the code
byte [] ImgInput = System.Text.Encoding.UTF8.GetBytes (ImgInputString); Convert string = imgString. ToBase64String (ImgInput); Byte [] imgBYtes = Convert.FromBase64String (imgString); System.IO.stream ms = (stream) new system. IOM Memorystream (imiginput); //ms.Write (imginput, 0, imiginput. Length); Image converter icc = new image controller (); Image image = (image) ic.ConvertFrom (imgBYtes); Error code
imageConverter to open image files Code> class is not used Use the Image.FromStream
method to open the data in the array:
image image; (MemoryStream M = New Memory Stream (IMGBIEs)) {image = Image.FromStream (m); }
Edit:
However, your first problem is how you encode the data. You are getting a string, which you can use as the UTF-8 encode , Then encode it as base-64, then decode it from Base-64. At that point, you still have a string that has been encoded as UTF-8, and there is nothing that you can load as an image, to convert data into Base-64 and back it up with data It is also not changed in any way.
If this is a base 64 encoded string that you receive as input, then you should only decode it:
byte [] imgBytes = Convert FromBase64String (ImgInputString);
If it is some other format, you have to decode it to get the encoded binary data before it can be sent to use the reverse process.
Comments
Post a Comment