Exemplo n.º 1
0
        static ImageResources()
        {
            var streamResourceInfo = Application.GetResourceStream(new Uri(CallWallIconPath));
            if (streamResourceInfo != null)
            {
                var iconStream = streamResourceInfo.Stream;
                CallWallIcon = new Icon(iconStream);
            }

            var conv = new ImageSourceConverter();
            if (conv.CanConvertFrom(typeof(string)))
            {
                CallWallLogoSource = (ImageSource)conv.ConvertFrom(CallWallLogoPath);
                CallWallImageSource = (ImageSource)conv.ConvertFrom(CallWallIconPath);
                BirthdayImageSource = (ImageSource)conv.ConvertFrom(BirthdayPath);
            }
        }
Exemplo n.º 2
0
		public void ConvertFromUri ()
		{
			Uri uri = new Uri ("tester.com", UriKind.Relative);
			ImageSourceConverter c = new ImageSourceConverter ();
			var converted = c.ConvertFrom (uri);
			Assert.IsInstanceOfType<BitmapImage> (converted, "#1");
			Assert.AreEqual (uri, ((BitmapImage) converted).UriSource, "#2");
		}
Exemplo n.º 3
0
        public static ImageSource ImageToSource(Image image)
        {
            MemoryStream stream = new MemoryStream();

            image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            System.Windows.Media.ImageBrush           imageBrush           = new System.Windows.Media.ImageBrush();
            System.Windows.Media.ImageSourceConverter imageSourceConverter = new System.Windows.Media.ImageSourceConverter();
            return((System.Windows.Media.ImageSource)imageSourceConverter.ConvertFrom(stream));
        }
Exemplo n.º 4
0
 public WaitingWindow()
 {
     InitializeComponent();
     this.Background = new SolidColorBrush(Color.FromRgb(188, 99, 163));
     MemoryStream stream = new MemoryStream();
     Properties.Resources.lrc.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
     ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
     this.Icon = (ImageSource)imageSourceConverter.ConvertFrom(stream);
     canCLose = false;
 }
Exemplo n.º 5
0
 /// <summary> 转换 Bitmap 到 ImageSource 
 /// Imaging.CreateBitmapSourceFromHBitmap 具有相同的功能,此项是通过数据流进行转换</summary>
 /// <param name="bitmap">将要转换的 Bitmap </param>
 /// <returns>转换后的 ImageSource </returns>
 public static ImageSource ConvertImageSource(this Bitmap bitmap)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
         ImageBrush imageBrush = new ImageBrush();
         ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
         return (ImageSource)imageSourceConverter.ConvertFrom(stream);
     }
 }
Exemplo n.º 6
0
		public void ConvertFromString_Absolute ()
		{
			ImageSourceConverter c = new ImageSourceConverter ();
			var converted = c.ConvertFrom ("http://example.com/image.jpg");
			Assert.IsInstanceOfType<BitmapImage> (converted, "#1");

			Uri uri = ((BitmapImage) converted).UriSource;
			Assert.AreEqual (new Uri ("http://example.com/image.jpg", UriKind.Absolute), uri, "#2");
			Assert.IsTrue (uri.IsAbsoluteUri, "#3");
		}
Exemplo n.º 7
0
		public void ConvertFromString_Relative ()
		{
			ImageSourceConverter c = new ImageSourceConverter ();
			var converted = c.ConvertFrom ("string");
			Assert.IsInstanceOfType<BitmapImage> (converted, "#1");

			Uri uri = ((BitmapImage) converted).UriSource;
			Assert.AreEqual (new Uri ("string", UriKind.Relative), uri, "#2");
			Assert.IsFalse (uri.IsAbsoluteUri, "#3");
		}
Exemplo n.º 8
0
 public SettingWindow()
 {
     InitializeComponent();
     this.Background = new SolidColorBrush(Color.FromRgb(213, 133, 191));
     MemoryStream stream = new MemoryStream();
     Properties.Resources.lrc.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
     ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
     this.Icon = (ImageSource)imageSourceConverter.ConvertFrom(stream);
     this.textBlock1.Text = Settings.Settings.Default.lrcDirectory;
     this.textBlock1.ToolTip = this.textBlock1.Text;
 }
Exemplo n.º 9
0
 public FolderBrowerDialog(Window window)
 {
     InitializeComponent();
     this.Owner = window;
     userSelectStatus = new _UserSelectStatus();
     userSelectStatus.cancel = true;
     userSelectStatus.selectedPath = "";
     MemoryStream stream = new MemoryStream();
     Properties.Resources.lrc.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
     ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
     this.Icon = (ImageSource)imageSourceConverter.ConvertFrom(stream);
 }
Exemplo n.º 10
0
 public MainWindow()
 {
     InitializeComponent();
     //folder icon init
     ImageSourceConverter c = new ImageSourceConverter();
     folderIcon = (ImageSource)c.ConvertFrom("pack://application:,,,/img/folderImage.png");
     entry = new Entry();
     
     ManagementObjectSearcher theSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE InterfaceType='USB'");
     foreach (ManagementObject currentObject in theSearcher.Get())
     {
         ManagementObject theSerialNumberObjectQuery = new ManagementObject("Win32_PhysicalMedia.Tag='" + currentObject["DeviceID"] + "'");
         MessageBox.Show(theSerialNumberObjectQuery["SerialNumber"].ToString());
     }
     //Request = new RequestManager();
     //watcher = new FileSystemWatcher();
 }
        private async Task<ImageSource> LoadImageSourceAsync(string address)
        {
            ImageSource imgSource = null;

            try
            {
                string url = EncodeUrl(address);
                MemoryStream ms = new MemoryStream(await new WebClient().DownloadDataTaskAsync(new Uri(url)));
                ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
                imgSource = (ImageSource)imageSourceConverter.ConvertFrom(ms);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
            }

            return imgSource;
        }
Exemplo n.º 12
0
        public MainWindow()
        {
            InitializeComponent();
            //folder icon init
            ImageSourceConverter c = new ImageSourceConverter();
            folderIcon = (ImageSource)c.ConvertFrom("pack://application:,,,/img/folderImage.png");

            //ContentManager.FileData fd = new ContentManager.FileData { FileName = "Test", FullPathStr = "C:\\Users\\Sohee\\Desktop\\Test" };
            //EntryElement ee = new EntryElement(EntryType.Folder, fd);
            //e = new Entry(ee);
            //e.makeEntry(); //에러발생

            //this.e.Meta.addKey("test1");
            //this.e.Meta.addKey("test2");
            //this.e.Meta.addKey("test3");
            //this.e.Meta.addKey("test4");
            
            //디폴트화면이 default가 아닌 경우 아래의 소스 필요
            //Category_TaglistBox.ItemsSource = this.e.Meta.getKeys();
                                        
        }
Exemplo n.º 13
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            BitmapSource bitmapSource = null;

            var uri = value as Uri;
            if (uri != null)
            {
                var imageSourceConverter = new ImageSourceConverter();
                var imageSource = imageSourceConverter.ConvertFrom(uri);
                bitmapSource = imageSource as BitmapSource;
            }

            if (bitmapSource == null)
            {
                bitmapSource = value as BitmapSource;
            }
            if (bitmapSource != null)
            {
                var converter = GetConverter(bitmapSource.Format);
                return converter.Convert(bitmapSource);
            }
            return value;
        }
Exemplo n.º 14
0
 /// <summary>
 /// 提取为图片源格式
 /// </summary>
 /// <param name="source">压缩源</param>
 /// <param name="path">关键字</param>
 /// <returns></returns>
 private ImageSource ExtractToImageSource(SevenZipArchive source, string path)
 {
     ArchiveEntry entry = source[path];
     MemoryStream stream = new MemoryStream();
     entry.Extract(stream);
     stream.Seek(0, SeekOrigin.Begin);
     ImageSourceConverter isc = new ImageSourceConverter();
     return (ImageSource)isc.ConvertFrom(stream);
 }
 public static ImageSource ConvertToImageSource(Bitmap bitmap)
 {
     var imageSourceConverter = new ImageSourceConverter();
     using (var memoryStream = new MemoryStream())
     {
         bitmap.Save(memoryStream, ImageFormat.Png);
         var snapshotBytes = memoryStream.ToArray();
         return (ImageSource)imageSourceConverter.ConvertFrom(snapshotBytes); ;
     }
 }
Exemplo n.º 16
0
        public MainWindow()
        {
            InitializeComponent();

            bool isFirst;
            mtx  = new System.Threading.Mutex
                                                               (true, "zjdd ", out   isFirst);

            #region Background color
            this.Background = new SolidColorBrush(Color.FromRgb(188, 99, 163));
            this.mainPanel.Background = this.Background;
            this.fileListView.Background = new SolidColorBrush(Color.FromRgb(213, 133, 191));
            this.about.Background = new SolidColorBrush(Color.FromRgb(213, 133, 191));
            this.lrcBox.Background = new SolidColorBrush(Color.FromRgb(213, 133, 191));
            this.lrcList.Background = new SolidColorBrush(Color.FromRgb(213, 133, 191));
            this.directoryTreeView.TreeViewBackground = new SolidColorBrush(Color.FromRgb(213, 133, 191));
            #endregion

            #region Initialize directory treeview contexmenu
            dirViewContextMenu = new ContextMenu();
            MenuItem menu = new MenuItem();
            menu.Header = "Add This Folder";
            menu.Click += new RoutedEventHandler(menu_Click);
            dirViewContextMenu.Items.Add(menu);
            MenuItem open = new MenuItem();
            open.Header = "Open Folder in Windows Explorer";
            open.Click += new RoutedEventHandler(open_Click);
            dirViewContextMenu.Items.Add(open);
            MenuItem properties = new MenuItem();
            properties.Header = "Properties";
            properties.Click += new RoutedEventHandler(properties_Click);
            dirViewContextMenu.Items.Add(properties);
            this.directoryTreeView.TreeViewContextMenu = dirViewContextMenu;
            #endregion

            #region Initialize mainwindow icon
            defaultPath = Settings.Settings.Default.lrcDirectory;//
            if ("" == defaultPath.Trim())
            {
                defaultPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ZDLRC\\";
                Settings.Settings.Default.lrcDirectory = defaultPath;
            }
            MemoryStream stream = new MemoryStream();
            Properties.Resources.lrc.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
            this.Icon = (ImageSource)imageSourceConverter.ConvertFrom(stream);

            Image image = new Image();
            image.Source = ImageHelper.ToBitmapSource(Properties.Resources.lrc);
            image.Height = image.Width = 64;

            #endregion

            #region delegate and thread
            fileList = new List<MusicFile>();
            lrcDownload = new LRCDownload();
            updateStatus = new UpdateStatus(UpdateSearchStatus);
            addLrcSelect = new AddLrcSelect(AddSearchLrc);
            addLrc = new AddLrc(AddDownloadLRC);
            failedList = new List<MusicFile>();
            searchLrcByZLP = new SearchLrcByZPL(SearchFromZLP);
            listViewFileList = new List<MusicFile>();
            fileList = new List<MusicFile>();
            lrcDownload = new LRCDownload();
            selectLRCBase = new LRCBase();
            scanComplete = new ScanComplete(ScanFinish);
            addFileToListView = new AddFileToListView(UpdateScanResult);
            backgroundWorker = new BackgroundWorker();
            backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
            backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
            #endregion

            #region Initialize aboutBox and load settings
            autoSelect.IsChecked = Settings.Settings.Default.autoSave;

            about.AppendText("LRC Download 1.0.0.1\n\n");
            about.AppendText("This is a free soft made by ZJ.\n");
            about.AppendText("If you have questions,please send me email:[email protected].\n");
            about.AppendText("Copyright© 2010-2012 of ZJSoft\n");
            new InlineUIContainer(image, about.Document.ContentEnd);
            #endregion

            #region Initialize lrcBox contexmenu
            InitLrcBoxContextMenu();
            #endregion

            #region Initialize fileListViewContextmenu
            fileListViewContextMenu = new ContextMenu();
            MenuItem clear = new MenuItem();
            clear.Header="Remove All Files";
            clear.Click += new RoutedEventHandler(clear_Click);
            fileListViewContextMenu.Items.Add(clear);
            fileListViewContextMenu.Opened += new RoutedEventHandler(fileListViewContextMenu_Opened);
            fileListView.ContextMenu = fileListViewContextMenu;
            #endregion

            ps = new PipeServer(this);
            psSer = new Thread(new ThreadStart(ps.StartPipeServer));
            psSer.Start();
            //MessageBox.Show(App.args);
            if (!String.IsNullOrEmpty(App.args))
            {
                string[] pas = App.args.Split('|');
                if (pas.Length >= 3)
                {
                    if (pas[0].Trim() == "0xFFFF")
                        pas[0] = "";
                    if (pas[1].Trim() == "0xFFFF")
                        pas[1] = "";

                    SearchFromZLP(pas[0], pas[1], pas[2]);
                }
            }
        }
Exemplo n.º 17
0
 public bool SetImageSource(string ImagePath)
 {
     ImageSourceConverter ISC = new ImageSourceConverter();
     if (ISC.CanConvertFrom(ImagePath.GetType()))
     {
         Image.ImageSource = (ImageSource)ISC.ConvertFrom(ImagePath);
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 18
0
		public void ConvertFromNull ()
		{
			ImageSourceConverter c = new ImageSourceConverter ();
			Assert.Throws<NotImplementedException> (() => c.ConvertFrom (null), "#1");
		}
Exemplo n.º 19
0
 /// <summary>
 /// 将获取到的图标信息转换为ImageSource
 /// </summary>
 /// <param name="pIcon"></param>
 /// <returns></returns>
 private ImageSource ConvertIcon(IntPtr pIcon)
 {
     System.IO.MemoryStream tempstream = new System.IO.MemoryStream();
     System.Drawing.Icon.FromHandle(pIcon).ToBitmap().Save(tempstream, System.Drawing.Imaging.ImageFormat.Png);
     ImageSourceConverter converter = new ImageSourceConverter();
     return (ImageSource)converter.ConvertFrom(tempstream);
 }
Exemplo n.º 20
0
 public FolderItem()
     : base()
 {
     ImageSourceConverter isc = new ImageSourceConverter();
     Image = isc.ConvertFrom("openfolderHS.png") as ImageSource;
 }
Exemplo n.º 21
0
        private void Init()
        {
            if (LicenseProvider.IsRegistered)
            {
                SerialNumberTextBox.Text = LicenseProvider.FormatSerialNumber(LicenseProvider.SerialNumber);
                SerialNumberTextBox.IsReadOnly = true;
                SerialNumberTextBox.MouseMove += CodeTextBox_MouseMove;
                RegisterButton.Visibility = Visibility.Collapsed;
                HelpTextBlock.Visibility = Visibility.Collapsed;
                return;
            }

            // 当应用程序没有以管理员权限运行时按钮显示盾牌
            if (!Common.IsAdmin())
            {
                // 由于在 WPF 中控件没有Handle,所以需要绘图实现
                // 先取出盾牌图标
                using (Icon icon = new Icon(SystemIcons.Shield, 12, 12))
                {
                    // 绘图
                    using (Bitmap bitmap = Bitmap.FromHicon(icon.Handle))
                    {
                        // 使之显示到界面
                        MemoryStream stream = new MemoryStream();
                        {
                            bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                            ImageBrush imageBrush = new ImageBrush();
                            ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
                            this.UACImage.Visibility = Visibility.Visible;
                            this.UACImage.Source = (ImageSource)imageSourceConverter.ConvertFrom(stream);
                        }
                    }
                }
            }
        }
Exemplo n.º 22
0
 public static ImageSource ImageToSource(Image image)
 {
     MemoryStream stream = new MemoryStream();
     image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
     System.Windows.Media.ImageBrush imageBrush = new System.Windows.Media.ImageBrush();
     System.Windows.Media.ImageSourceConverter imageSourceConverter = new System.Windows.Media.ImageSourceConverter();
     return (System.Windows.Media.ImageSource)imageSourceConverter.ConvertFrom(stream);
 }
    private static ImageSource ConvertFromByteArray( byte[] imageBytes )
    {
      ImageSource imageSource = null;

      try
      {
        ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
        imageSource = imageSourceConverter.ConvertFrom( imageBytes ) as ImageSource;
      }
      catch
      {
      }

      return imageSource;
    }
Exemplo n.º 24
0
        private void btnStudent_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                //Trained face counter
                ContTrain = ContTrain + 1;

                //Get a gray frame from capture device
                gray = grabber.QueryGrayFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

                //Face Detector
                MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
                face,
                1.2,
                10,
                Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                new System.Drawing.Size(20, 20));

                if (facesDetected == null || facesDetected.Length <= 0)
                {
                    MessageBox.Show("Not able detect any face, try again");
                    dispatcherTimer.Start();
                }

                //Action for each element detected
                foreach (MCvAvgComp f in facesDetected[0])
                {
                    t = t + 1;
                    result = currentFrame.Copy(f.rect).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                    //draw the face detected in the 0th (gray) channel with blue color
                    currentFrame.Draw(f.rect, new Bgr(System.Drawing.Color.Red), 2);
                    dispatcherTimer.Stop();
                    break;
                }

                TrainedFace = result.Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                trainingImages.Add(TrainedFace);
                //labels.Add(textBox1.Text);

                ImageSourceConverter c = new ImageSourceConverter();
                ImageSource srcImage = c.ConvertFrom(TrainedFace.ToBitmap()) as ImageSource;
                //Show face added in gray scale
                imageBox1.Source = srcImage;

                var startupPath = Environment.CurrentDirectory;
                //Write the number of triained faces in a file text for further load
                File.WriteAllText(startupPath + "/TrainedFaces/TrainedLabels.txt", trainingImages.ToArray().Length.ToString() + "%");

                //Write the labels of triained faces in a file text for further load
                for (int i = 1; i < trainingImages.ToArray().Length + 1; i++)
                {
                    trainingImages.ToArray()[i - 1].Save(startupPath + "/TrainedFaces/face" + i + ".bmp");
                    File.AppendAllText(startupPath + "/TrainedFaces/TrainedLabels.txt", labels.ToArray()[i - 1] + "%");
                }

               // MessageBox.Show(textBox1.Text + "´s face detected and added :)", "Training OK", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch
            {
                MessageBox.Show("Enable the face detection first", "Training Fail", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
        private ImageSource GetThumbnail()
        {
            var renderTarget = new RenderTargetBitmap(581, 420, 96, 96, PixelFormats.Pbgra32);
            renderTarget.Render(DisplayCanvas);
            BitmapFrame bitmapFrame = BitmapFrame.Create(renderTarget);
            var encoder = new PngBitmapEncoder();
            encoder.Frames.Add(bitmapFrame);

            var converter = new ImageSourceConverter();
            var baseImageStream = new MemoryStream();

            encoder.Save(baseImageStream);

            var bitmap = (Bitmap)System.Drawing.Image.FromStream(baseImageStream);

            var cropped = bitmap.Clone(new Rectangle(226, 65, 355, 355), System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            var resized = new Bitmap(75, 75);
            Graphics g = Graphics.FromImage(resized);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.DrawImage(cropped, 0, 0, 75, 75);
            g.Dispose();

            var croppedAndResizedStream = new MemoryStream();

            resized.Save(croppedAndResizedStream, ImageFormat.Png);
            var from = converter.ConvertFrom(croppedAndResizedStream);
            var source = (ImageSource)from;

            return source;
        }
Exemplo n.º 26
0
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Trained face counter
                ContTrain = ContTrain + 1;

                //Get a gray frame from capture device
                gray = grabber.QueryGrayFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

                //Face Detector
                MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
                face,
                1.2,
                10,
                Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                new System.Drawing.Size(20, 20));

                TrainedFace = result.Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                trainingImages.Add(TrainedFace);
                //labels.Add(textBox1.Text);

                ImageSourceConverter c = new ImageSourceConverter();
                ImageSource srcImage = c.ConvertFrom(TrainedFace.ToBitmap()) as ImageSource;
                //Show face added in gray scale
                imageBox1.Source = srcImage;

                var startupPath = Environment.CurrentDirectory;
                //Write the number of triained faces in a file text for further load
                File.WriteAllText(startupPath + "/TrainedFaces/TrainedLabels.txt", trainingImages.ToArray().Length.ToString() + "%");

                //Write the labels of triained faces in a file text for further load
                for (int i = 1; i < trainingImages.ToArray().Length + 1; i++)
                {
                    trainingImages.ToArray()[i - 1].Save(startupPath + "/TrainedFaces/face" + i + ".bmp");
                    File.AppendAllText(startupPath + "/TrainedFaces/TrainedLabels.txt", labels.ToArray()[i - 1] + "%");
                }

               // MessageBox.Show(textBox1.Text + "´s face detected and added :)", "Training OK", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch
            {
                MessageBox.Show("Enable the face detection first", "Training Fail", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }