|
@@ -1,5 +1,7 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Drawing;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
@@ -12,7 +14,10 @@ using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Navigation;
|
|
|
using System.Windows.Shapes;
|
|
|
+using Microsoft.Win32;
|
|
|
+using MyWpfApp.models;
|
|
|
using MyWpfApp.Pages;
|
|
|
+using static System.Net.Mime.MediaTypeNames;
|
|
|
|
|
|
namespace MyWpfApp
|
|
|
{
|
|
@@ -21,12 +26,52 @@ namespace MyWpfApp
|
|
|
/// </summary>
|
|
|
public partial class MainWindow : Window
|
|
|
{
|
|
|
+ ImageBindings imageBindings = new ImageBindings();
|
|
|
public MainWindow()
|
|
|
{
|
|
|
+
|
|
|
+ DataContext = imageBindings;
|
|
|
+
|
|
|
+
|
|
|
InitializeComponent();
|
|
|
+
|
|
|
FrmMain.Navigate(new Auth());
|
|
|
Globals.MyGlobalFrame = FrmMain;
|
|
|
Globals.MyGlobalConnection = new Smerdova_PPEntities();
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Button_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ OpenFileDialog OFD = new OpenFileDialog();
|
|
|
+ OFD.Filter = "Все файлы | *.*; | Изображения |*.jpg;*.png;";
|
|
|
+ bool? success = OFD.ShowDialog();
|
|
|
+
|
|
|
+
|
|
|
+ ImageConverter imageConverter = new ImageConverter();
|
|
|
+
|
|
|
+ //создаем объект изображения по известному пути к картинке
|
|
|
+ System.Drawing.Image image = System.Drawing.Image.FromFile(OFD.FileName);
|
|
|
+
|
|
|
+ //преобразуем картинку в массив байт
|
|
|
+ byte[] bytes = (byte[])imageConverter.ConvertTo(image, typeof(byte[]));
|
|
|
+
|
|
|
+
|
|
|
+ //преобразуем массив байт в BitmapImage (т.к. его можно помещать в ImageSource)
|
|
|
+ using (MemoryStream stream = new MemoryStream(bytes))
|
|
|
+ {
|
|
|
+ var BMimage = new BitmapImage();
|
|
|
+ BMimage.BeginInit();
|
|
|
+ BMimage.CacheOption = BitmapCacheOption.OnLoad;
|
|
|
+ BMimage.StreamSource = stream;
|
|
|
+ BMimage.EndInit();
|
|
|
+ imageBindings.ImageSource = BMimage;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ imageBindings.ImgPath = OFD.FileName;
|
|
|
+ MessageBox.Show(imageBindings.ImgPath);
|
|
|
}
|
|
|
}
|
|
|
}
|