toByteArray() public method

public toByteArray ( ) : byte[]
return byte[]
Example #1
0
        private void sendScreenshotToWatchers(int client_index, Screenshot screenshot)
        {
            //Create a list of valid watchers
            List<int> watcher_indices = new List<int>();

            for (int i = 0; i < clients.Length; i++)
            {
            if (clientIsReady(i) && clients[i].activityLevel != ServerClient.ActivityLevel.INACTIVE)
            {
                bool match = false;

                lock (clients[i].watchPlayerNameLock)
                {
                    match = clients[i].watchPlayerName == clients[client_index].username;
                }

                if (match)
                    watcher_indices.Add(i);
            }
            }

            if (watcher_indices.Count > 0)
            {
            //Build the message and send it to all watchers
            byte[] message_bytes = buildMessageArray(KLFCommon.ServerMessageID.SCREENSHOT_SHARE, screenshot.toByteArray());
            foreach (int i in watcher_indices)
            {
                clients[i].queueOutgoingMessage(message_bytes);
            }
            }
        }
Example #2
0
        private void shareScreenshot()
        {
            //Determine the scaled-down dimensions of the screenshot
            int w = 0;
            int h = 0;

            KLFScreenshotDisplay.screenshotSettings.getBoundedDimensions(Screen.width, Screen.height, ref w, ref h);

            //Read the screen pixels into a texture
            Texture2D full_screen_tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
            full_screen_tex.filterMode = FilterMode.Bilinear;
            full_screen_tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
            full_screen_tex.Apply();

            RenderTexture render_tex = new RenderTexture(w, h, 24);
            render_tex.useMipMap = false;

            if (KLFGlobalSettings.instance.smoothScreens && (Screen.width > w * 2 || Screen.height > h * 2))
            {
                //Blit the full texture to a double-sized texture to improve final quality
                RenderTexture resize_tex = new RenderTexture(w * 2, h * 2, 24);
                Graphics.Blit(full_screen_tex, resize_tex);

                //Blit the double-sized texture to normal-sized texture
                Graphics.Blit(resize_tex, render_tex);
            }
            else
                Graphics.Blit(full_screen_tex, render_tex); //Blit the screen texture to a render texture

            full_screen_tex = null;

            RenderTexture.active = render_tex;

            //Read the pixels from the render texture into a Texture2D
            Texture2D resized_tex = new Texture2D(w, h, TextureFormat.RGB24, false);
            resized_tex.ReadPixels(new Rect(0, 0, w, h), 0, 0);
            resized_tex.Apply();

            RenderTexture.active = null;

            byte[] data = resized_tex.EncodeToPNG();

            Screenshot screenshot = new Screenshot();
            screenshot.player = playerName;
            if (FlightGlobals.ready && FlightGlobals.ActiveVessel != null)
                screenshot.description = FlightGlobals.ActiveVessel.vesselName;
            screenshot.image = data;

            Debug.Log("Sharing screenshot");
            enqueuePluginInteropMessage(KLFCommon.PluginInteropMessageID.SCREENSHOT_SHARE, screenshot.toByteArray());
        }
Example #3
0
 private void sendScreenshot(int client_index, Screenshot screenshot)
 {
     clients[client_index].queueOutgoingMessage(KLFCommon.ServerMessageID.SCREENSHOT_SHARE, screenshot.toByteArray());
 }