private void TestImage_Click(object sender, RoutedEventArgs e) { string testfile = ""; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = @"C:\Users\cgarcia\Documents\Cesar Garcia_files\University\CPEG585 - ComputerVision\ATTFaceDataSet\Testing"; if (openFileDialog.ShowDialog() == false) { return; } testfile = openFileDialog.FileName; Bitmap testimg = new Bitmap(testfile); PaintImage(ImgCheck, testimg); PaintImage(AdjImg, pca.CenterImage(testimg)); PaintImage(ReconstImage, pca.ReconstructImage(testimg)); pca.Match(testimg); Bitmap[] matches = pca.GetMatchedImages(); int cntr = 0; foreach (Bitmap bmp in matches) { System.Windows.Controls.Image image = (System.Windows.Controls.Image) this.FindName($"Match{cntr}"); cntr++; PaintImage(image, bmp); } }
public static void ApplyLogo(System.Windows.Controls.Image LogoBox, TLogo ThemeLogoBox) { if (ThemeLogoBox.Image.Path != "") { LogoBox.Source = ConvertImage(ThemeLogoBox.Image); } }
public bool getImage(byte[] pFotoByte, System.Windows.Controls.Image pImageControl) { try { byte[] buffer = (byte[])pFotoByte; MemoryStream stream = new MemoryStream(); stream.Write(buffer, 0, buffer.Length); stream.Position = 0; System.Drawing.Image img = System.Drawing.Image.FromStream(stream); BitmapImage bi = new BitmapImage(); bi.BeginInit(); MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); bi.StreamSource = ms; bi.EndInit(); pImageControl.Source = bi; return(true); } catch { return(false); } }
private static void Canvas_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { Canvas canvas = (Canvas)sender; Grid grid = (Grid)canvas.Children[0]; System.Windows.Controls.TextBlock label = grid.Children[1] as System.Windows.Controls.TextBlock; System.Windows.Controls.TextBlock label1 = grid.Children[2] as System.Windows.Controls.TextBlock; System.Windows.Controls.TextBlock label2 = grid.Children[3] as System.Windows.Controls.TextBlock; System.Windows.Controls.Image image = (System.Windows.Controls.Image)grid.Children[0]; (((((canvas.Parent as StackPanel).Parent as ScrollViewer).Parent as Grid).Parent as Canvas).Children[1] as System.Windows.Controls.Image).Source = image.Source; (((((canvas.Parent as StackPanel).Parent as ScrollViewer).Parent as Grid).Parent as Canvas).Children[2] as System.Windows.Controls.Label).Content = label.Text; (((((canvas.Parent as StackPanel).Parent as ScrollViewer).Parent as Grid).Parent as Canvas).Children[3] as System.Windows.Controls.Label).Content = label1.Text; (((((canvas.Parent as StackPanel).Parent as ScrollViewer).Parent as Grid).Parent as Canvas).Children[4] as System.Windows.Controls.Label).Content = label2.Text; }
/// <summary> /// Generate thumbnail from image and add it to last shots taken menu /// </summary> /// <param name="path"></param> /// <returns></returns> public StackPanel CreatePreviewThumbnail(string path) { StackPanel sp = new StackPanel(); sp.Orientation = System.Windows.Controls.Orientation.Horizontal; System.Windows.Controls.Image Img = new System.Windows.Controls.Image(); Img.Width = 150; Img.Height = 150; Img.Source = new BitmapImage(new Uri(path)); sp.Children.Add(Img); sp.Margin = new Thickness(2, 0, 2, 50); Img.MouseDown += new MouseButtonEventHandler(OnThumbnailsClick); m_ThumbnailsList.Add(sp); return(sp); }
private void PaintImage(System.Windows.Controls.Image imageToPaint, Bitmap bmp) { System.IO.MemoryStream stream = new System.IO.MemoryStream(); bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); stream.Position = 0; byte[] data = new byte[stream.Length]; stream.Read(data, 0, Convert.ToInt32(stream.Length)); BitmapImage bmapImage = new BitmapImage(); bmapImage.BeginInit(); bmapImage.StreamSource = stream; bmapImage.EndInit(); imageToPaint.Source = bmapImage; imageToPaint.Stretch = Stretch.Uniform; }
private void CalcEF_Click(object sender, RoutedEventArgs e) { pca = new PCA(traindir); pca.GetPCA(); TestImage.IsEnabled = true; CompAcc.IsEnabled = true; int cntr = 0; foreach (Bitmap img in pca.GetEigenFaces().Take(5)) { System.Windows.Controls.Image currev = (System.Windows.Controls.Image) this.FindName($"EV{cntr}"); cntr++; PaintImage(currev, img); } MessageBox.Show("Primary Component Analysis Completed"); }
private void InitializeComponent() { var containerGrid = new System.Windows.Controls.Grid(); //containerGrid.ToolTip = FillPattern.Name; var patternImage = new System.Windows.Controls.Image(); var imageSourceBinding = new System.Windows.Data.Binding(); imageSourceBinding.Path = new PropertyPath("FillPatternImage"); imageSourceBinding.Converter = new BitmapToImageSourceConverter(); imageSourceBinding.RelativeSource = new System.Windows.Data.RelativeSource(System.Windows.Data.RelativeSourceMode.FindAncestor, typeof(FillPatternViewerControl), ancestorLevel: 1); System.Windows.Data.BindingOperations.SetBinding(patternImage, System.Windows.Controls.Image.SourceProperty, imageSourceBinding); containerGrid.Children.Add(patternImage); this.AddChild(containerGrid); }
public static Canvas newAdCanvas(string Title, string Body, string Footer, ImageSource image) { Canvas canvas = new Canvas(); Grid grid = new Grid(); canvas.MinHeight = 50; canvas.MinWidth = 315; grid.MinHeight = 50; grid.MinWidth = 315; TextBlock tbTitle = new TextBlock(); TextBlock tbBody = new TextBlock(); TextBlock tbFooter = new TextBlock(); System.Windows.Controls.Image img = new System.Windows.Controls.Image(); img.MinWidth = 50; img.MinHeight = 50; img.Width = 50; img.Height = 50; img.Source = image; img.Stretch = Stretch.UniformToFill; img.HorizontalAlignment = HorizontalAlignment.Left; tbTitle.HorizontalAlignment = HorizontalAlignment.Left; tbTitle.Margin = new Thickness(60, 0, 0, 0); tbBody.HorizontalAlignment = HorizontalAlignment.Left; tbBody.Margin = new Thickness(60, 15, 0, 0); tbFooter.HorizontalAlignment = HorizontalAlignment.Left; tbFooter.Margin = new Thickness(60, 30, 0, 0); canvas.MouseDown += Canvas_MouseDown; tbTitle.Text = Title; tbBody.Text = Body; tbFooter.Text = Footer; grid.Children.Add(img); grid.Children.Add(tbTitle); grid.Children.Add(tbBody); grid.Children.Add(tbFooter); Grid.SetColumn(img, 0); Grid.SetColumn(tbTitle, 0); Grid.SetColumn(tbBody, 0); Grid.SetColumn(tbFooter, 0); Grid.SetRow(img, 0); Grid.SetRow(tbTitle, 0); Grid.SetRow(tbBody, 0); Grid.SetRow(tbFooter, 0); canvas.Children.Add(grid); return canvas; }
private void ExecutingLoadingImagesEveryHour() { button.IsEnabled = false; listView.Items.Clear(); if (!string.IsNullOrEmpty(EnvVariables.SrcPath)) { // Chech destanation directory (create if not exists) this.ChechDestDirectory(); // Get source directory information DirectoryInfo srcDirInfo = new DirectoryInfo(EnvVariables.SrcPath); // get all files from source directory FileInfo[] fileInfos = srcDirInfo.GetFiles(); // Index of image on UI int index = 0; foreach (var fileInfo in fileInfos) { try { var oldFileName = Path.Combine(EnvVariables.SrcPath, fileInfo.Name); var image = Image.FromFile(oldFileName); if (image.Height >= Constants.FullHdHeight && image.Width >= Constants.FullHdWidth) { var newFileName = Path.Combine(EnvVariables.DestPath, string.Format(fileInfo.Name + ".jpeg")); if (File.Exists(newFileName) || ContainsImage(image)) { continue; } File.Copy(oldFileName, newFileName); AddToListExistImages(image); var canvas = FindVisualChildren <Canvas>(groupBox).FirstOrDefault(); if (canvas != null) { BitmapImage bitmapImage = GetThumbnailBitmapImage(newFileName); var uiElement = new System.Windows.Controls.Image() { Source = bitmapImage }; Canvas.SetLeft(uiElement, GetIndentLeft(index)); Canvas.SetTop(uiElement, GetIndentTop(index)); canvas.Children.Add(uiElement); index++; } listView.Items.Add(newFileName); } } catch (Exception) { // MessageBox.Show(exception.Message); } } } button.IsEnabled = true; }
/// <summary> /// Generate thumbnail from image and add it to last shots taken menu /// </summary> /// <param name="path"></param> /// <returns></returns> public StackPanel CreatePreviewThumbnail(string path) { StackPanel sp = new StackPanel(); sp.Orientation = System.Windows.Controls.Orientation.Horizontal; System.Windows.Controls.Image Img = new System.Windows.Controls.Image(); Img.Width = 150; Img.Height = 150; Img.Source = new BitmapImage(new Uri(path)); sp.Children.Add(Img); sp.Margin = new Thickness(2, 0, 2, 50); Img.MouseDown += new MouseButtonEventHandler(OnThumbnailsClick); m_ThumbnailsList.Add(sp); return sp; }