示例#1
0
        public Bitmap ReceiveImage()
        {
            int      receivedPackages = 0;
            ImageBit image            = Deserialize(client.Receive());

            ImageBit[] arrStructs = new ImageBit[image.NumberBits];
            arrStructs[image.CurrentBit] = image;
            int imageNumber = image.ImageNumber;

            receivedPackages++;
            while (true)
            {
                image = Deserialize(client.Receive());
                if (imageNumber == image.ImageNumber)
                {
                    receivedPackages++;
                    arrStructs[image.CurrentBit] = image;
                    if ((receivedPackages == (image.NumberBits)) && (imageNumber == image.ImageNumber))
                    {
                        client.SendResponse(response);
                        return(AssemblyBitmap(arrStructs, image.Size));
                    }
                }
                else
                {
                    imageNumber = image.ImageNumber;
                    arrStructs  = new ImageBit[image.NumberBits];
                    arrStructs[image.CurrentBit] = image;
                    receivedPackages             = 1;
                }
            }
        }
示例#2
0
        public void SendImage(Bitmap bmp, int imageNumber)
        {
            int count = 0, currentBit = 0;

            byte[] arr        = StreamToArray(ScreenCapture.VaryQualityLevel(bmp));
            int    numberBits = (arr.Length / PackageSize) + ((arr.Length % PackageSize) == 0 ? 0 : 1);

            while (count < arr.Length)
            {
                int    arrLength = (arr.Length - count) > PackageSize ? PackageSize : arr.Length - count;
                byte[] tempArr   = new byte[arrLength];
                Array.Copy(arr, count, tempArr, 0, arrLength);
                ImageBit bit = new ImageBit()
                {
                    NumberBits  = numberBits,
                    CurrentBit  = currentBit++,
                    Data        = tempArr,
                    ImageNumber = imageNumber,
                    Size        = arr.Length
                };
                tempArr = Serialize(bit);
                count  += arrLength;
                client.Send(tempArr);
            }
        }
示例#3
0
        private byte[] Serialize(ImageBit image)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream    ms        = new MemoryStream();

            formatter.Serialize(ms, image);
            return(StreamToArray(ms));
        }