コード例 #1
0
ファイル: Program.cs プロジェクト: xxy1991/cozy
        private static void Main(string[] args)
        {
            //var r = CaptureUtil.DefGetCaptureData(ref offset, ref width, ref height);
            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);

                // 4k / 4 = 1k
                // sqrt(1024) = 32
                int num             = 0;
                const int blockSize = 128;
                var bitmap          = new BITMAP();
                var bitmapSize      = CaptureUtil.DefGetCaptureBlockBitmap(hwnd, hdc, 0, 0, blockSize, blockSize, ref bitmap);
                int blockSizeW      = (x + blockSize - 1) / blockSize;
                int blockSizeH      = (y + blockSize - 1) / blockSize;
                for (int i = 0; i < blockSizeW; ++i)
                {
                    for (int j = 0; j < blockSizeH; ++j)
                    {
                        var r       = CaptureUtil.DefGetCaptureData(hwnd, hdc, bitmapSize, bitmap, i * blockSize, j * blockSize, blockSize, blockSize);
                        var result  = CaptureUtil.ConvertBmpToJpeg(r);
                        using (FileStream fs = new FileStream(@"D:\Test\test" + num + @".jpg", FileMode.Create, FileAccess.Write))
                        {
                            fs.Write(result, 0, result.Length);
                        }
                        ++num;
                    }
                }
            }
        }
コード例 #2
0
ファイル: CaptureUtil.cs プロジェクト: xxy1991/cozy
        public static byte[] DefGetCaptureData(IntPtr hwnd, IntPtr hdc, uint size, BITMAP bmp, int x, int y, int w, int h)
        {
            uint offset = 0;
            byte[] data = new byte[size];
            offset      = AppendBitmapHeader(ref data[0], ref bmp);

            if (offset == 0)
            {
                return null;
            }
            if (GetCaptureData(hwnd, hdc, x, y, w, h, ref data[offset]) == 0)
            {
                return null;
            }
            return data;
        }
コード例 #3
0
ファイル: CapturePluginMethods.cs プロジェクト: xxy1991/cozy
        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,
                },
            };
        }
コード例 #4
0
ファイル: CaptureUtil.cs プロジェクト: xxy1991/cozy
 public static uint DefGetCaptureBlockBitmap(IntPtr hwnd, IntPtr hdc, int x, int y, int w, int h, ref BITMAP bmp)
 {
     return GetCaptureDataSize(hwnd, hdc, x, y, w, h, ref bmp);
 }
コード例 #5
0
ファイル: CaptureUtil.cs プロジェクト: xxy1991/cozy
 public static extern uint GetCaptureDataSize(IntPtr hwnd, IntPtr hdc, int x, int y, int w, int h, ref BITMAP bmp);
コード例 #6
0
ファイル: CaptureUtil.cs プロジェクト: xxy1991/cozy
 public static extern uint AppendBitmapHeader(ref byte data, ref BITMAP bitmap);