-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
64 lines (58 loc) · 1.87 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Microsoft.Win32;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows;
namespace BinaryCodeToImageConverter
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private string PathToFile;
private int Resolution;
public MainWindow()
{
InitializeComponent();
}
private void SourceFileButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
var result = dialog.ShowDialog();
if(result.Value == true)
{
PathToFile = dialog.FileName;
}
}
private void GenerateFileButton_Click(object sender, RoutedEventArgs e)
{
PixelFormat format = PixelFormat.Format32bppRgb;
if(IsTransparentCheckBox.IsChecked.Value)
{
format = PixelFormat.Format32bppArgb;
}
Bitmap image = new Bitmap(Resolution, Resolution, format);
Drawer drawer = new Drawer(image);
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "png file |*.png";
var result = dialog.ShowDialog();
drawer.DrawToBitmap(PathToFile);
if(result.Value)
{
image.Save(dialog.FileName, ImageFormat.Png);
}
}
private void ResolutionTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
try
{
Resolution = int.Parse(ResolutionTextBox.Text);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Ow, there is an error!", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}