Hey guys,
I'm trying to send an image taken from my webcam to a web API for processing.
So I take a screenshot and store it in a Texture2D variable, then convert that to a byte[] by calling EncodeToPNG().
What kind of ContentType should I set for this?
None of the ones I've tried seem to work.
This is my HttpWebRequest code:
myWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:64050/api/ZXing/BeginDecode");
myWebRequest.Method = "POST";
//Set ContentType here
myWebRequest.ContentLength = bytes.Length;
Stream dataStream = myWebRequest.GetRequestStream();
dataStream.Write(bytes, 0, bytes.Length);
dataStream.Close();
response = myWebRequest.GetResponse();
Stream data = response.GetResponseStream();
StreamReader reader = new StreamReader(data);
Debug.Log(reader.ReadToEnd());
Here's my camera code, just incase:
camSnapshot = new Texture2D(camTex.width, camTex.height, TextureFormat.RGB24, false);
camSnapshot.SetPixels(camTex.GetPixels());
camSnapshot.Apply();
bytes = camSnapshot.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/../SavedScreen.png",bytes);
Making and working with Web APIs are new to me so sorry if it's a dumb problem.
Thanks.
↧