Esempio n. 1
0
        internal static BitmapHandle CreateDIBSection(HandleRef hdc, ref InteropValues.BITMAPINFO bitmapInfo, int iUsage,
                                                      ref IntPtr ppvBits, SafeFileMappingHandle hSection, int dwOffset)
        {
            if (hSection == null)
            {
                hSection = new SafeFileMappingHandle(IntPtr.Zero);
            }

            var hBitmap = PrivateCreateDIBSection(hdc, ref bitmapInfo, iUsage, ref ppvBits, hSection, dwOffset);

            return(hBitmap);
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
 internal static extern IntPtr CreateDIBSection(IntPtr hdc, ref InteropValues.BITMAPINFO pbmi, uint iUsage, out IntPtr ppvBits, IntPtr hSection, uint dwOffset);
Esempio n. 4
0
 private static extern BitmapHandle PrivateCreateDIBSection(HandleRef hdc, ref InteropValues.BITMAPINFO bitmapInfo, int iUsage,
                                                            ref IntPtr ppvBits, SafeFileMappingHandle hSection, int dwOffset);