Exemple #1
0
        public void SendImg(Bitmap bmp)
        {
            Bitmap toSend     = bmp;
            bool   deltaframe = false;

            if (LastScreen != null)
            {
                deltaframe = true;
                toSend     = Stuff.Diff(LastScreen, bmp);
            }
            LastScreen = Stuff.CloneViaCopyBytes(bmp);
            writer.WriteLine("FRAME;" + (deltaframe ? "DELTA" : "FULL"));
            writer.Flush();
            MemoryStream ms = new MemoryStream();

            toSend.Save(ms, ImageFormat.Png);

            var detid     = 0;
            int chunkSize = 1024 * 10;
            var bts       = ms.ToArray();

            for (int i = 0; i < bts.Length; i += chunkSize)
            {
                var    last = bts.Length - i;
                var    arr  = bts.Skip(i).Take(Math.Min(last, chunkSize)).ToArray();
                string str2 = "CHUNK=" + detid + ";" + bts.Length + ";" + arr.Length + ";" + i + ";";
                var    b64  = Convert.ToBase64String(arr);
                var    md5  = Stuff.CreateMD5(b64);
                str2 += b64 + ";" + md5;

                writer.WriteLine(str2);
                writer.Flush();
            }
            ms.Dispose();
            writer.WriteLine("IMGEND");
            writer.Flush();
        }