예제 #1
0
        internal static IconHandle CreateIconCursor(byte[] colorArray, int width, int height, int xHotspot, int yHotspot, bool isIcon)
        {
            BitmapHandle colorBitmap = null;
            BitmapHandle maskBitmap  = null;

            try
            {
                var bi = new InteropValues.BITMAPINFO(width, -height, 32)
                {
                    biCompression = InteropValues.BI_RGB
                };

                var bits = IntPtr.Zero;
                colorBitmap = InteropMethods.CreateDIBSection(new HandleRef(null, IntPtr.Zero), ref bi, InteropValues.DIB_RGB_COLORS, ref bits, null, 0);

                if (colorBitmap.IsInvalid || bits == IntPtr.Zero)
                {
                    return(IconHandle.GetInvalidIcon());
                }

                Marshal.Copy(colorArray, 0, bits, colorArray.Length);
                var maskArray = GenerateMaskArray(width, height, colorArray);

                maskBitmap = InteropMethods.CreateBitmap(width, height, 1, 1, maskArray);
                if (maskBitmap.IsInvalid)
                {
                    return(IconHandle.GetInvalidIcon());
                }

                var iconInfo = new InteropValues.ICONINFO
                {
                    fIcon    = isIcon,
                    xHotspot = xHotspot,
                    yHotspot = yHotspot,
                    hbmMask  = maskBitmap,
                    hbmColor = colorBitmap
                };

                return(InteropMethods.CreateIconIndirect(iconInfo));
            }
            finally
            {
                colorBitmap?.Dispose();
                maskBitmap?.Dispose();
            }
        }
예제 #2
0
    internal GlowBitmap(IntPtr hdcScreen, int width, int height)
    {
        _bitmapInfo.biSize          = Marshal.SizeOf(typeof(InteropValues.BITMAPINFOHEADER));
        _bitmapInfo.biPlanes        = 1;
        _bitmapInfo.biBitCount      = 32;
        _bitmapInfo.biCompression   = 0;
        _bitmapInfo.biXPelsPerMeter = 0;
        _bitmapInfo.biYPelsPerMeter = 0;
        _bitmapInfo.biWidth         = width;
        _bitmapInfo.biHeight        = -height;

        Handle = InteropMethods.CreateDIBSection(
            hdcScreen,
            ref _bitmapInfo,
            0u,
            out _pbits,
            IntPtr.Zero,
            0u);
    }