Using Client.SendBytes to stream between apps
I'm developing an app for college which is meant to interact and stream itself into another app. I used a Server/Client structure to do so, and everything works, except for the image transfer.
I used the following code on the client:
Texture2D tex = ScreenCapture.CaptureScreenshotAsTexture (1);
tex.Apply ();
byte[] data = tex.EncodeToPNG ();
client.SendBytes (data, data.Length, 0);
And this on the server to read it:
Texture2D tex = new Texture2D (200, 200, TextureFormat.RGBA32, false);
byte[] data = reader.ReadBytesAndSize ();
tex.LoadImage(data);
//tex.LoadRawTextureData (data);
tex.Apply ();
Sprite sp = Sprite.Create (tex, new Rect (0, 0, tex.width, tex.height), new Vector2 (.5f, .5f), 100);
img.sprite = sp;
When I use LoadImage, i end up with a black background and a red "?", when I use loadrawtexturedata, I just get a gray image.
Answer by thelghome · Jul 02, 2019 at 12:56 PM
Usually, if your byte[] of image is not received completely, you will get a red "?". I recommended you this plugin, which will be a good example for you.
FM Exhibition Tool Pack | Forum
Provides demos of in-game view/live video, audio streaming solution. All codes are written in C# and you can freely customise for your own project.
Your answer
Follow this Question
Related Questions
How should I verify that all of my client Object are created and ready after loading a new scene? 0 Answers
NetworkManager:The client can`t bound to the specified port? 0 Answers
NetworkServer.Send and NetworkClient.Send or synchronising on player prefab? 0 Answers
non-player object can't execute's "[Command]"'s attributes 0 Answers
How to create a self-named text box above the .max file? 1 Answer