Exemplo n.º 1
0
 public CapturePluginPageViewModel()
 {
     clientCore                          = MainWindowViewModel.clientCore;
     clientCore.CaptureRefreshHandler    += new System.EventHandler<CaptureRefreshEventArgs>(OnCaptureRefresh);
     GlobalBMP                           = new Bitmap(((1366 + 127) / 128 * 128), ((768 + 127) / 128) * 128);
     GlobalLocker                        = new BitmapLocker(GlobalBMP);
 }
Exemplo n.º 2
0
        private void OnCaptureRefresh(object sender, CaptureRefreshEventArgs msg)
        {
            using (MemoryStream ms = new MemoryStream(msg.Data))
            {
                int x = msg.MetaData.Item1;
                int y = msg.MetaData.Item2;

                Bitmap recvbmp          = (Bitmap)Image.FromStream(ms);
                BitmapLocker recvdata   = new BitmapLocker(recvbmp);

                recvdata.LockBits();
                GlobalLocker.LockBits();


                for(int i = 0; i < recvdata.Width; ++i)
                {
                    for (int j = 0; j < recvdata.Height; ++j)
                    {
                        GlobalLocker.SetPixel(i + x, j + y, recvdata.GetPixel(i, j));
                    }
                }

                GlobalLocker.UnlockBits();
                recvdata.UnlockBits();

                using (MemoryStream ims = new MemoryStream())
                {
                    GlobalBMP.Save(ims, ImageFormat.Bmp);
                    ims.Seek(0, SeekOrigin.Begin);

                    BitmapImage bm  = new BitmapImage();
                    bm.BeginInit();
                    bm.StreamSource = ims;
                    bm.CacheOption  = BitmapCacheOption.OnLoad;
                    bm.EndInit();
                    CaptureImage    = bm;
                }
            }
        }
Exemplo n.º 3
0
        public PluginMethodReturnValueType Shell(GetCaptureDataArgs CopyArgs)
        {
            List<ReturnValuePacket> result = new List<ReturnValuePacket>();

            IntPtr hwnd = IntPtr.Zero;
            IntPtr hdc = IntPtr.Zero;

            if (CaptureUtil.GetWindowHDC(ref hwnd, ref hdc))
            {
                int x = 0;
                int y = 0;
                CaptureUtil.GetWindowSize(hwnd, ref x, ref y);

                const int blockSize = 128;
                int blockSizeW      = (x + blockSize - 1) / blockSize;
                int blockSizeH      = (y + blockSize - 1) / blockSize;
                var bitmap          = new BITMAP();
                var bitmapSize      = CaptureUtil.DefGetCaptureBlockBitmap(hwnd, hdc, 0, 0, 0, 0, ref bitmap);
                var bmp = CaptureUtil.DefGetCaptureData(hwnd, hdc, bitmapSize, bitmap, 0, 0, x, y);
                using (MemoryStream ms = new MemoryStream(bmp))
                {
                    var pic = (Bitmap)Image.FromStream(ms);
                    var locker = new BitmapLocker(pic);
                    locker.LockBits();
                    for (int i = 0; i < blockSizeW; ++i)
                    {
                        for (int j = 0; j < blockSizeH; ++j)
                        {
                            Bitmap outputBmp = new Bitmap(blockSize, blockSize);
                            var outputLocker = new BitmapLocker(outputBmp);
                            outputLocker.LockBits();
                            int blockBeginX = i * blockSize;
                            int blockBeginY = j * blockSize;
                            int blockWidth  = (i + 1) * (blockSize) > x ? (x % blockSize) : blockSize;
                            int blockHeight = (j + 1) * (blockSize) > y ? (y % blockSize) : blockSize;
                            for (int k = 0; k < blockWidth; ++k)
                            {
                                for (int l = 0; l < blockHeight; ++l)
                                {
                                    outputLocker.SetPixel(k, l, locker.GetPixel(blockBeginX + k, blockBeginY + l));
                                }
                            }
                            outputLocker.UnlockBits();
                            using (MemoryStream oms = new MemoryStream())
                            {
                                outputBmp.Save(oms, ImageFormat.Jpeg);
                                byte[] data = new byte[oms.Length];
                                oms.Seek(0, SeekOrigin.Begin);
                                oms.Read(data, 0, data.Length);
                                var meta = new CaptureSplitMetaData()
                                {
                                    X = blockBeginX,
                                    Y = blockBeginY,
                                    Width = blockSize,
                                    Height = blockSize,
                                };

                                var m = JsonConvert.SerializeObject(meta);
                                result.Add(new ReturnValuePacket()
                                {
                                    MetaData = m,
                                    Data = data,
                                });
                            }
                        }
                    }
                    locker.UnlockBits();
                }
            }

            return new PluginMethodReturnValueType()
            {
                DataType    = PluginMethodReturnValueType.PacketBinaryDataType,
                Data        = new PluginMehtodReturnValuePacket()
                {
                    Packet = result,
                },
            };
        }