Example #1
0
 private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.V))
     {
         if (Clipboard.ContainsImage())
         {
             Bitmap tmp = ImgConverter.BitmapFromSource(Clipboard.GetImage());
             SetThumbnail(ImgConverter.ResizeImage(tmp, MainWindow.thumbnailSize));
             tmp?.Dispose();
         }
     }
 }
Example #2
0
        private void InsertImageFromClipboard(bool Refresh)
        {
            if ((!editable) || (!System.Windows.Clipboard.ContainsImage()))
            {
                return;
            }

            Element newFile  = null;
            ushort  maxTries = 3;

            do
            {
                try
                {
                    Bitmap tmp = ImgConverter.BitmapFromSource(System.Windows.Clipboard.GetImage());
                    using (MemoryStream stream = new MemoryStream())
                    {
                        //tmp1 через який баг в GDI, не хоче працювати з tmp
                        Bitmap tmp1 = new Bitmap(tmp);
                        tmp1.Save(stream, ImageFormat.Jpeg);
                        tmp1?.Dispose();
                        Bitmap icon     = ImgConverter.ResizeImage(tmp, thumbnailSize);
                        string FileName = DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + ".jpg";

                        if (isCompareImage)
                        {
                            var duplicates = GetDuplicates(FileName, icon);
                            if (duplicates.Count > 0)
                            {
                                ShowDuplicateFilesList(duplicates, FileName, icon);
                                icon?.Dispose();
                                tmp?.Dispose();
                                return;
                            }
                        }

                        stream.Position = 0;
                        try
                        {
                            newFile = (listView.Tag as DirElement)?.AddFile(stream, FileName, false, icon);
                        }
                        catch (Exception e)
                        {
                            Refresh = false;
                            System.Windows.MessageBox.Show(e.Message);
                        }
                        icon?.Dispose();
                        maxTries = 0;
                    }
                    tmp?.Dispose();
                }
                catch (ExternalException ex)
                {
                    maxTries--;
                }
            } while (maxTries > 0);

            if (Refresh && newFile != null)
            {
                ShowFiles(listView.Tag as Element, newFile);
            }

            if (clipboardClean_CheckBox.IsChecked == true)
            {
                System.Windows.Clipboard.Clear();
            }
        }