Screenshot.toByteArray C# (CSharp) Method

toByteArray() public method

public toByteArray ( ) : byte[]
return byte[]
    public byte[] toByteArray()
    {
        UnicodeEncoding encoding = new UnicodeEncoding();
        byte[] player_bytes = encoding.GetBytes(player);
        byte[] description_bytes = encoding.GetBytes(description);
        byte[] bytes = new byte[12 + player_bytes.Length + description_bytes.Length + image.Length];

        int array_index = 0;
        KLFCommon.intToBytes(index).CopyTo(bytes, array_index);
        array_index += 4;

        KLFCommon.intToBytes(player_bytes.Length).CopyTo(bytes, array_index);
        array_index += 4;

        player_bytes.CopyTo(bytes, array_index);
        array_index += player_bytes.Length;

        KLFCommon.intToBytes(description_bytes.Length).CopyTo(bytes, array_index);
        array_index += 4;

        description_bytes.CopyTo(bytes, array_index);
        array_index += description_bytes.Length;

        image.CopyTo(bytes, array_index);

        return bytes;
    }

Usage Example

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);
            }
            }
        }
All Usage Examples Of Screenshot::toByteArray