Exemplo n.º 1
0
        private static BitmapSource GetImageFromHierarchy(HierarchyItemIdentity item, int iconIndexProperty, int iconHandleProperty)
        {
            int          iconIndex;
            IntPtr       iconHandle;
            IntPtr       iconImageList;
            BitmapSource iconBitmapSource = null;

            IVsHierarchy iconSourceHierarchy = item.Hierarchy;
            uint         iconSourceItemid    = item.ItemID;

            if (item.IsNestedItem)
            {
                bool useNestedHierarchyIconList;
                if (TryGetHierarchyProperty(item.Hierarchy, item.ItemID, (int)__VSHPROPID2.VSHPROPID_UseInnerHierarchyIconList, out useNestedHierarchyIconList) && useNestedHierarchyIconList)
                {
                    iconSourceHierarchy = item.NestedHierarchy;
                    iconSourceItemid    = item.NestedItemID;
                }
            }

            if (TryGetHierarchyProperty(iconSourceHierarchy, iconSourceItemid, iconIndexProperty, out iconIndex) &&
                TryGetHierarchyProperty(iconSourceHierarchy, VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_IconImgList, UnboxAsIntPtr, out iconImageList))
            {
                NativeImageList imageList = new NativeImageList(iconImageList);
                iconBitmapSource = imageList.GetImage(iconIndex);
            }
            else if (TryGetHierarchyProperty(item.Hierarchy, item.ItemID, iconHandleProperty, UnboxAsIntPtr, out iconHandle))
            {
                // Don't call DestroyIcon on iconHandle, as it's a shared resource owned by the hierarchy
                iconBitmapSource = Imaging.CreateBitmapSourceFromHIcon(iconHandle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                iconBitmapSource.Freeze();
            }

            if (iconBitmapSource == null)
            {
                iconBitmapSource = GetSystemIconImage(item);
            }

            return(iconBitmapSource);
        }
Exemplo n.º 2
0
        public BitmapSource ToBitmapSource(Bitmap bitmap)
        {
            var ip           = bitmap.GetHbitmap();
            var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(ip, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            NativeMethods.DeleteObject(ip);
            return(bitmapSource);
        }
Exemplo n.º 3
0
        public static BitmapSource CaptureRegion(Int32Rect region)
        {
            IntPtr       desktophWnd;
            IntPtr       desktopDc;
            IntPtr       memoryDc;
            IntPtr       bitmap;
            IntPtr       oldBitmap;
            bool         success;
            BitmapSource result;

            desktophWnd = GetDesktopWindow();
            desktopDc   = GetWindowDC(desktophWnd);
            memoryDc    = CreateCompatibleDC(desktopDc);
            bitmap      = CreateCompatibleBitmap(desktopDc, region.Width, region.Height);
            oldBitmap   = SelectObject(memoryDc, bitmap);

            success = BitBlt(memoryDc, 0, 0, region.Width, region.Height, desktopDc, region.X, region.Y, SRCCOPY | CAPTUREBLT);

            try
            {
                if (!success)
                {
                    throw new Win32Exception();
                }

                result = Imaging.CreateBitmapSourceFromHBitmap(bitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            }
            finally
            {
                SelectObject(memoryDc, oldBitmap);
                DeleteObject(bitmap);
                DeleteDC(memoryDc);
                ReleaseDC(desktophWnd, desktopDc);
            }

            return(result);
        }
Exemplo n.º 4
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            Bitmap oldbitmap = ImageCovert(PhotoPresent.Singleton.imageContainer);
            Bitmap newbitmap = new Bitmap(oldbitmap.Width, oldbitmap.Height);

            System.Drawing.Color pixel;

            int[] Laplacian = { -1, -1, -1, -1, 9, -1, -1, -1, -1 };
            for (int x = 1; x < oldbitmap.Width - 1; x++)
            {
                for (int y = 1; y < oldbitmap.Height - 1; y++)
                {
                    int r = 0, g = 0, b = 0;
                    int Index = 0;
                    for (int col = -1; col <= 1; col++)
                    {
                        for (int row = -1; row <= 1; row++)
                        {
                            pixel = oldbitmap.GetPixel(x + row, y + col); r += pixel.R * Laplacian[Index];
                            g    += pixel.G * Laplacian[Index];
                            b    += pixel.B * Laplacian[Index];
                            Index++;
                        }
                    }

                    r = r > 255 ? 255 : r;
                    r = r < 0 ? 0 : r;
                    g = g > 255 ? 255 : g;
                    g = g < 0 ? 0 : g;
                    b = b > 255 ? 255 : b;
                    b = b < 0 ? 0 : b;
                    newbitmap.SetPixel(x - 1, y - 1, System.Drawing.Color.FromArgb(r, g, b));
                }
            }

            PhotoPresent.Singleton.imageContainer.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(newbitmap.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(newbitmap.Width, newbitmap.Height));
        }
Exemplo n.º 5
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            System.Drawing.Color pixel;


            Bitmap oldbitmap = ImageCovert(PhotoPresent.Singleton.imageContainer);
            Bitmap newbitmap = new Bitmap(oldbitmap.Width, oldbitmap.Height);

            for (int x = 1; x < oldbitmap.Width; x++)
            {
                for (int y = 1; y < oldbitmap.Height; y++)
                {
                    int r, g, b;
                    pixel = oldbitmap.GetPixel(x, y);
                    r     = 255 - pixel.R;
                    g     = 255 - pixel.G;
                    b     = 255 - pixel.B;
                    newbitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(r, g, b));
                }
            }

            PhotoPresent.Singleton.imageContainer.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(newbitmap.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(newbitmap.Width, newbitmap.Height));
        }
Exemplo n.º 6
0
        public static BitmapSource ToBitmapSource(this Bitmap bitmap)
        {
            IntPtr hBitmap      = bitmap.GetHbitmap();
            var    bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            DeleteObject(hBitmap);
            return(bitmapSource);
        }
Exemplo n.º 7
0
 private static ImageSource IconToImageSource(Icon icon)
 {
     return(Imaging.CreateBitmapSourceFromHIcon(icon.Handle, new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions()));
 }
Exemplo n.º 8
0
        public Result OnStartup(UIControlledApplication application)
        {
            try
            {
                //TAF load english_us TODO add a way to localize
                res = Resource_en_us.ResourceManager;
                // Create new ribbon panel
                RibbonPanel ribbonPanel = application.CreateRibbonPanel(res.GetString("App_Description"));

                //Create a push button in the ribbon panel
                var pushButton = ribbonPanel.AddItem(new PushButtonData("Dynamo",
                                                                        res.GetString("App_Name"), m_AssemblyName,
                                                                        "Dynamo.Applications.DynamoRevit")) as
                                 PushButton;

                Bitmap dynamoIcon = Resources.Nodes_32_32;


                BitmapSource bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(
                    dynamoIcon.GetHbitmap(),
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromEmptyOptions());

                pushButton.LargeImage = bitmapSource;
                pushButton.Image      = bitmapSource;

#if DEBUG
                var pushButton1 = ribbonPanel.AddItem(new PushButtonData("Test",
                                                                         res.GetString("App_Name"), m_AssemblyName,
                                                                         "Dynamo.Applications.DynamoRevitTester")) as PushButton;
                pushButton1.LargeImage = bitmapSource;
                pushButton1.Image      = bitmapSource;
#endif

                // MDJ = element level events and dyanmic model update
                // MDJ 6-8-12  trying to get new dynamo to watch for user created ref points and re-run definition when they are moved

                IdlePromise.RegisterIdle(application);

                updater = new DynamoUpdater(application.ActiveAddInId, application.ControlledApplication);
                if (!UpdaterRegistry.IsUpdaterRegistered(updater.GetUpdaterId()))
                {
                    UpdaterRegistry.RegisterUpdater(updater);
                }

                var SpatialFieldFilter           = new ElementClassFilter(typeof(SpatialFieldManager));
                var familyFilter                 = new ElementClassFilter(typeof(FamilyInstance));
                var refPointFilter               = new ElementCategoryFilter(BuiltInCategory.OST_ReferencePoints);
                var modelCurveFilter             = new ElementClassFilter(typeof(CurveElement));
                var sunFilter                    = new ElementClassFilter(typeof(SunAndShadowSettings));
                IList <ElementFilter> filterList = new List <ElementFilter>();

                filterList.Add(SpatialFieldFilter);
                filterList.Add(familyFilter);
                filterList.Add(modelCurveFilter);
                filterList.Add(refPointFilter);
                filterList.Add(sunFilter);

                ElementFilter filter = new LogicalOrFilter(filterList);

                UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter, Element.GetChangeTypeAny());
                UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter, Element.GetChangeTypeElementDeletion());
                UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter, Element.GetChangeTypeElementAddition());

                env = new ExecutionEnvironment();
                //EnsureApplicationResources();

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(Result.Failed);
            }
        }
Exemplo n.º 9
0
        public static ImageSource GetIcon(string path, bool smallIcon)
        {
            bool isFileOrDirectoryValid = false;
            bool isDirectory            = false;

            if (System.IO.File.Exists(path))
            {
                isFileOrDirectoryValid = true;
            }
            else
            {
                if (System.IO.Directory.Exists(path))
                {
                    isFileOrDirectoryValid = true;
                    isDirectory            = true;
                }
            }

            if (!isFileOrDirectoryValid)
            {
                return(null);
            }

            uint flags = SHGFI_ICON | SHGFI_USEFILEATTRIBUTES;

            if (smallIcon)
            {
                flags |= SHGFI_SMALLICON;
            }

            uint attributes = FILE_ATTRIBUTE_NORMAL;

            if (isDirectory)
            {
                attributes |= FILE_ATTRIBUTE_DIRECTORY;
            }

            SHFILEINFO shfi;

            if (0 != SHGetFileInfo(path, attributes, out shfi, (uint)Marshal.SizeOf(typeof(SHFILEINFO)), flags))
            {
                return(System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(shfi.hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
            }
            return(null);
        }
        /// <summary>
        /// Function that handles the setting up of all the images in the pane.
        /// </summary>
        private void SetupImageSources()
        {
            textColorIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                Properties.Resources.TextColor_icon.GetHbitmap(),
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            lineColorIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                Properties.Resources.LineColor_icon.GetHbitmap(),
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            fillColorIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                Properties.Resources.FillColor_icon.GetHbitmap(),
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            eyeDropperIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                Properties.Resources.EyeDropper_icon.GetHbitmap(),
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            brightnessIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                Properties.Resources.Brightness_icon_25x25.GetHbitmap(),
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            saturationIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                Properties.Resources.Saturation_icon_18x18.GetHbitmap(),
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            saveColorIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                Properties.Resources.Save_icon.GetHbitmap(),
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            loadColorIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                Properties.Resources.Load_icon.GetHbitmap(),
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            reloadColorIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                Properties.Resources.Reload_icon.GetHbitmap(),
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());

            clearColorIcon.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                Properties.Resources.Clear_icon.GetHbitmap(),
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());
        }
Exemplo n.º 11
0
        static public BitmapSource getBitmapSourceFromBitmap(Bitmap bmp)
        {
            BitmapSource returnSource = null;

            try
            {
                returnSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(),

                                                                                            IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            }

            catch { returnSource = null; }

            return(returnSource);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Upload drug image
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uploadButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.DefaultExt = ".jpg";
            dialog.Filter     = "JPG Files|*.jpg|JPEG Files|*.jpeg | PNG Files|*.png|GIF Files|*.gif";
            if (dialog.ShowDialog() == true)
            {
                uploadButton.IsEnabled = false;
                string filename = (dialog.FileName);
                if (new System.IO.FileInfo(filename).Length <= 184320)
                {
                    try
                    {
                        img = new System.Drawing.Bitmap(filename);
                    }
                    catch (Exception) { MessageBox.Show("Failed to read file", "TeleMedicine", MessageBoxButton.OK, MessageBoxImage.Error); }

                    if (img != null)
                    {
                        System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
                        edit_img      = (byte[])converter.ConvertTo(img, typeof(byte[]));
                        image1.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(img.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        MessageBox.Show("Image upload completed", "TeleMedicine", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Image upload failed", "TeleMedicine", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Image upload failed. File size limit is 180kb", "TeleMedicine", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                uploadButton.IsEnabled = true;
            }
        }
Exemplo n.º 13
0
        public static BitmapSource ConvertBitmapToSource(Bitmap bitmap, bool dispose = false)
        {
            IntPtr handle = bitmap.GetHbitmap();

            try {
                return(Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
            }
            finally {
                NativeMethods.DeleteObject(handle);
                if (dispose)
                {
                    bitmap.Dispose();
                }
            }
        }
Exemplo n.º 14
0
            public BitmapSource GetImage(int index)
            {
                if (index >= ImageListCount || index < 0)
                {
                    return(null);
                }

                // generate the ImageSource from the native HIMAGELIST handle
                IntPtr hIcon = NativeMethods.ImageList_GetIcon(ImageListHandle, index, NativeMethods.ILD_TRANSPARENT);

                if (hIcon == IntPtr.Zero)
                {
                    return(null);
                }

                try
                {
                    // Int32Rect.Empty means use the dimensions of the source image
                    BitmapSource image = Imaging.CreateBitmapSourceFromHIcon(hIcon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    image.Freeze();
                    return(image);
                }
                finally
                {
                    NativeMethods.DestroyIcon(hIcon);
                }
            }
Exemplo n.º 15
0
        public void RenderImage()
        {
            if (Canvas == null)
            {
                return;
            }

            void Render()
            {
                IntPtr hBmp = Bmp.GetHbitmap();

                Canvas.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBmp, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                Canvas.Source.Freeze();
                DeleteObject(hBmp);
            }

            Canvas.Dispatcher.BeginInvoke(new Action(Render)).Wait();
        }
 private void WindowLoaded(object sender, RoutedEventArgs e)
 {
     this.RemoveSystemMenuItems(Win32.SystemMenuItems.All); //去除窗口指定的系统菜单
     TitleLbl.Content   = $"雾化处理: {_factor}";
     _resultBitmap      = GetHandledImage(_cacheFirstBitmap, _factor);
     _writeableBitmap   = new WriteableBitmap(Imaging.CreateBitmapSourceFromHBitmap(_resultBitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
     TargetImage.Source = _writeableBitmap;
 }
Exemplo n.º 17
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     image.Source = Imaging.CreateBitmapSourceFromHBitmap(worldMap.GetMapTexture().GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
 }
Exemplo n.º 18
0
        /// <summary>
        /// Converts an Icon to a BitmapSource.
        /// </summary>
        /// <param name="value">Value to be converted.</param>
        /// <param name="targetType">Type to convert to.</param>
        /// <param name="parameter">Optional conversion parameter.</param>
        /// <param name="culture">Globalization info.</param>
        /// <returns>Object with type of BitmapSource. If conversion cannot take place, returns null.</returns>
        public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            if (value is Process)
            {
                value = (value as Process)?.GetIcon();
            }

            if (value is Icon)
            {
                Bitmap bitmap       = (value as Icon)?.ToBitmap();
                IntPtr bitmaphandle = bitmap?.GetHbitmap() ?? IntPtr.Zero;

                if (bitmaphandle != IntPtr.Zero)
                {
                    return(Imaging.CreateBitmapSourceFromHBitmap(bitmaphandle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
                }
            }

            return(null);
        }
Exemplo n.º 19
0
        public static ImageSource ToImageSource(this Icon icon)
        {
            Bitmap      bitmap    = icon.ToBitmap();
            IntPtr      hBitmap   = bitmap.GetHbitmap();
            ImageSource wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            if (!DeleteObject(hBitmap))
            {
                throw new Win32Exception();
            }
            return(wpfBitmap);
        }
Exemplo n.º 20
0
        private System.Windows.Media.ImageSource ConvertImgControl(System.Drawing.Image _img)
        //method to convert Image type from Drawing.Image to Windows.Controls.Image
        {
            System.Windows.Controls.Image img = new System.Windows.Controls.Image();

            //convert System.Drawing.Image to WPF image
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(_img);
            IntPtr hBitmap            = bmp.GetHbitmap();

            System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap,
                                                                                                                      IntPtr.Zero,
                                                                                                                      Int32Rect.Empty,
                                                                                                                      BitmapSizeOptions.FromEmptyOptions());

            return(WpfBitmap);
        }
Exemplo n.º 21
0
        public static ImageSource ToImageSource(this Bitmap bitmap)
        {
            var handle = bitmap.GetHbitmap();

            try
            {
                return(Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()));
            }
            finally { DeleteObject(handle); }
        }
Exemplo n.º 22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private static BitmapSource GetIconFromPath(string?path)
        {
            path = path ?? string.Empty;

            BitmapSource?bitmap;

            // need to lock before trying to get the value else we get duplicates because of concurrency
            lock (procIconLstLocker)
            {
                if (!procIconLst.TryGetValue(path, out bitmap))
                {
                    Icon?ic = null;
                    try
                    {
                        switch (path)
                        {
                        case "System":
                            ic = SystemIcons.WinLogo;
                            break;

                        case "-":
                            ic = SystemIcons.WinLogo;
                            break;

                        case "":
                        case "?error":     //FIXME: Use something else?
                        case "Unknown":
                            ic = SystemIcons.Error;
                            break;

                        default:
                            if (!path.Contains(@"\", StringComparison.Ordinal))
                            {
                                LogHelper.Debug($"Skipped extract icon: '{path}' because path has no directory info.");
                                ic = SystemIcons.Application;
                                break;
                            }
                            try
                            {
                                ic = Icon.ExtractAssociatedIcon(path);
                            }
                            catch (ArgumentException)
                            {
                                LogHelper.Debug("Unable to extract icon: " + path);
                                ic = SystemIcons.Application;
                            }
                            catch (System.IO.FileNotFoundException)     //Undocumented exception
                            {
                                LogHelper.Debug("Unable to extract icon: " + path);
                                ic = SystemIcons.Warning;
                            }
                            break;
                        }

                        ic = ic ?? SystemIcons.Application;

                        //FIXME: Resize the icon to save some memory?
                        bitmap = Imaging.CreateBitmapSourceFromHIcon(ic.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        bitmap.Freeze();
                        procIconLst.Add(path, bitmap);
                    }
                    finally
                    {
                        ic?.Dispose();
                    }
                }
            }
            return(bitmap);
        }
Exemplo n.º 23
0
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            Bitmap oldbitmap = ImageCovert(PhotoPresent.Singleton.imageContainer);
            Bitmap newbitmap = new Bitmap(oldbitmap.Width, oldbitmap.Height);


            RectangleF rect = new RectangleF(0, 0, oldbitmap.Width, oldbitmap.Height);
            Bitmap     img  = oldbitmap.Clone(rect, System.Drawing.Imaging.PixelFormat.DontCare);

            Random rnd = new Random();

            int iModel = 2;
            int i      = oldbitmap.Width - iModel;

            while (i > 1)
            {
                int j = oldbitmap.Height - iModel;
                while (j > 1)
                {
                    int iPos = rnd.Next(100000) % iModel;

                    System.Drawing.Color color = img.GetPixel(i + iPos, j + iPos);
                    img.SetPixel(i, j, color);
                    j = j - 1;
                }
                i = i - 1;
            }

            PhotoPresent.Singleton.imageContainer.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(img.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(newbitmap.Width, newbitmap.Height));
        }
Exemplo n.º 24
0
 public static BitmapSource?ToBitmapSource(IntPtr hIcon, bool destoryIcon = true) => ToBitmapSource(hIcon, BitmapSizeOptions.FromEmptyOptions(), destoryIcon);
Exemplo n.º 25
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Bitmap oldbitmap = ImageCovert(PhotoPresent.Singleton.imageContainer);
            Bitmap newbitmap = new Bitmap(oldbitmap.Width, oldbitmap.Height);

            System.Drawing.Color pixel1, pixel2;
            for (int x = 0; x < oldbitmap.Width - 1; x++)
            {
                for (int y = 0; y < oldbitmap.Height - 1; y++)
                {
                    int r = 0, g = 0, b = 0;
                    pixel1 = oldbitmap.GetPixel(x, y);
                    pixel2 = oldbitmap.GetPixel(x + 1, y + 1);
                    r      = Math.Abs(pixel1.R - pixel2.R + 128);
                    g      = Math.Abs(pixel1.G - pixel2.G + 128);
                    b      = Math.Abs(pixel1.B - pixel2.B + 128);
                    if (r > 255)
                    {
                        r = 255;
                    }
                    if (r < 0)
                    {
                        r = 0;
                    }
                    if (g > 255)
                    {
                        g = 255;
                    }
                    if (g < 0)
                    {
                        g = 0;
                    }
                    if (b > 255)
                    {
                        b = 255;
                    }
                    if (b < 0)
                    {
                        b = 0;
                    }
                    newbitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(r, g, b));
                }
            }

            PhotoPresent.Singleton.imageContainer.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(newbitmap.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(newbitmap.Width, newbitmap.Height));
        }
Exemplo n.º 26
0
 public static BitmapSource?ToBitmapSource(this System.Drawing.Icon icon) => ToBitmapSource(icon, BitmapSizeOptions.FromEmptyOptions());
Exemplo n.º 27
0
        public static ImageSource Extract(string destination, string url, bool isDirectory)
        {
            Shell32.SHFILEINFO shinfo = new Shell32.SHFILEINFO();
            ImageSource        imageSource;
            string             alternatePath = destination;
            bool   deleteFile    = false;
            string ext           = Path.GetExtension(destination);
            string shortFilename = Path.GetFileName(destination);
            Icon   icon;

            // have we seen these before?
            if (isDirectory && _icons.ContainsKey(destination))
            {
                _icons.TryGetValue(destination, out imageSource);
                return(imageSource);
            }
            else if (!isDirectory && ext != ".exe" && _icons.ContainsKey(ext))
            {
                _icons.TryGetValue(ext, out imageSource);
                return(imageSource);
            }
            else if (!isDirectory && ext == ".exe" && _icons.ContainsKey(shortFilename))
            {
                _icons.TryGetValue(shortFilename, out imageSource);
                return(imageSource);
            }

            // check paths and create temp files if necessary
            if (isDirectory && !Directory.Exists(destination))
            {
                alternatePath = AppDomain.CurrentDomain.BaseDirectory;
            }
            else if (!isDirectory && !File.Exists(destination))
            {
                ext           = Path.GetExtension(destination).ToLower();
                alternatePath = Path.GetTempPath() + Path.DirectorySeparatorChar + "AMDownloader" + DateTime.Now.ToFileTimeUtc() + "." + ext;
                File.Create(alternatePath).Close();
                deleteFile = true;
            }

            // grab the actual icons
            if (!isDirectory)
            {
                // file icon
                icon = Icon.ExtractAssociatedIcon(alternatePath);
            }
            else
            {
                // folder icon
                Shell32.SHGetFileInfo(
                    alternatePath,
                    Shell32.FILE_ATTRIBUTE_NORMAL,
                    ref shinfo,
                    (uint)Marshal.SizeOf(shinfo),
                    Shell32.SHGFI_ICON | Shell32.SHGFI_LARGEICON);

                icon = Icon.FromHandle(shinfo.hIcon);
            }

            // create the image from the icon
            imageSource = Imaging.CreateBitmapSourceFromHIcon(
                icon.Handle,
                new Int32Rect(0, 0, icon.Width, icon.Height),
                BitmapSizeOptions.FromEmptyOptions());

            // save the keys and images
            if (isDirectory && !_icons.ContainsKey(alternatePath))
            {
                _icons.Add(alternatePath, imageSource);
            }
            else
            {
                if (ext != ".exe" && !_icons.ContainsKey(ext))
                {
                    _icons.Add(ext, imageSource);
                }
                else if (ext == ".exe" && File.Exists(destination))
                {
                    _icons.Add(shortFilename, imageSource);
                }
            }

            if (deleteFile)
            {
                File.Delete(alternatePath);
            }

            if (isDirectory)
            {
                User32.DestroyIcon(shinfo.hIcon);
            }

            return(imageSource);
        }
Exemplo n.º 28
0
 public static BitmapSource?ToBitmapSource(this System.Drawing.Icon icon, BitmapSizeOptions bitmapSizeOptions) => ToBitmapSource(icon.Handle, bitmapSizeOptions, false);
Exemplo n.º 29
0
        public static BitmapSource BitmapToBitmapSource(Bitmap bitmap)

        {
            intPointer   = bitmap.GetHbitmap();
            bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(intPointer, IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            DeleteObject(intPointer);
            return(bitmapSource);
        }
        //生成base64
        //private string ToBase64Encode(string text)
        //{
        //    if (String.IsNullOrEmpty(text))
        //    {
        //        return text;
        //    }

        //    byte[] textBytes = Encoding.UTF8.GetBytes(text);
        //    return Convert.ToBase64String(textBytes);
        //}

        //生成QRcoder图片
        private void CreateQRCode(string varBase64)
        {
            //string varBase64 = varBase64;
            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            QRCodeData      qrCodeData  = qrGenerator.CreateQrCode(varBase64, QRCodeGenerator.ECCLevel.Q);
            QRCode          qrCode      = new QRCode(qrCodeData);
            Bitmap          qrCodeImage = qrCode.GetGraphic(20);
            IntPtr          myImagePtr  = qrCodeImage.GetHbitmap();
            BitmapSource    imgsource   = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(myImagePtr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            ImageTrojanShareQRurl.Source = imgsource;
            //DeleteObject(myImagePtr);
            qrCodeImage.Save($"trojan_config\\{saveFileFolder}\\QR.bmp");
        }