Zobrazení obrázku kódem:
using System; using System.Collections.Generic; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication1 { ////// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var img = new Image { Width = 100, Height = 100 }; img.Source = LoadBitmap(global::WpfApplication1.Properties.Resources._2_9); paretoGrid.Children.Add(img); } public static BitmapImage LoadBitmap(System.Drawing.Bitmap input) { using (MemoryStream memory = new MemoryStream()) { input.Save(memory, ImageFormat.Png); memory.Position = 0; BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = memory; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); return bitmapImage; } } } }
Zobrazení bez resources:
public MainWindow() { InitializeComponent(); var img = new Image { Width = 300, Height = 300 }; BitmapImage image = new BitmapImage( new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, "obrazky/1-8.png"))); img.Source = image; paretoGrid.Children.Add(img); }
a změnit vlastnosti: