Ejemplo n.º 1
0
        protected override void OnExecute(object parameter)
        {
            var s = new Bitmap(Properties.Resources.png_undo_16_16);

            var w = new TestWindow
            {
                Background = Brushes.Green,
                Grid       =
                {
                    Margin     = new Thickness(50),
                    Background = Brushes.Red
                }
            };


            var b = ImageThemingUtilities.GetThemedBitmap(s, ImageThemingUtilities.GetImageBackgroundColor(w.Grid).ToRgba());

            BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                b.GetHbitmap(),
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromWidthAndHeight(b.Width, b.Height));

            w.Icon = bs;


            w.ShowDialog();


            //new FolderBrowserDialog().ShowDialog();
        }
Ejemplo n.º 2
0
        private static Bitmap GetInvertedBitmap(Microsoft.VisualStudio.Shell.Interop.IVsUIShell5 shell5,
            Bitmap inputBitmap, Color transparentColor, uint backgroundColor)
#endif
        {
            Bitmap outputBitmap = null;
            try
            {
#if VS2015
                outputBitmap = ImageThemingUtilities.GetThemedBitmap(inputBitmap, backgroundColor);
#else
                byte[] outputBytes;
                Rectangle rect;
                System.Drawing.Imaging.BitmapData bitmapData;
                IntPtr sourcePointer;
                int length;

                outputBitmap = new Bitmap(inputBitmap);

                outputBitmap.MakeTransparent(transparentColor);

                rect = new Rectangle(0, 0, outputBitmap.Width, outputBitmap.Height);

                bitmapData = outputBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, outputBitmap.PixelFormat);

                sourcePointer = bitmapData.Scan0;

                length = (Math.Abs(bitmapData.Stride) * outputBitmap.Height);

                outputBytes = new byte[length];

                Marshal.Copy(sourcePointer, outputBytes, 0, length);

                shell5.ThemeDIBits( (UInt32)outputBytes.Length, outputBytes, (UInt32)outputBitmap.Width,
                                   (UInt32)outputBitmap.Height, true, backgroundColor);

                Marshal.Copy(outputBytes, 0, sourcePointer, length);

                outputBitmap.UnlockBits(bitmapData);
#endif
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return outputBitmap;

        }