Example #1
0
        private void BitmapToClient(int width, int height, int x, int y, int start, int stride, bool cursor, byte [] img)
        {
            GCHandle handle = GCHandle.Alloc(img, GCHandleType.Pinned);

            try
            {
                IntPtr pointer = Marshal.UnsafeAddrOfPinnedArrayElement(img, start);
                using (Bitmap bitmap = new Bitmap(width, height, stride, cursor ? pixelFormatCursor : pixelFormat, pointer))
                {
                    if (cursor)
                    {
                        client.ClientSetCursor(bitmap, x, y, width, height);
                    }
                    else
                    {
                        client.ClientDrawImage(bitmap, x, y, width, height);
                    }
                }
            }
            catch (ArgumentException exn)
            {
                Log.Error(exn, exn);
            }
            finally
            {
                handle.Free();
            }
        }