-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResizeImages.cs
229 lines (187 loc) · 7.85 KB
/
ResizeImages.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Globalization;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
// StreamDeck Mini: 216px 144px
// StreamDeck MK2: 360px 216px
// StreamDeck +: 360px 144px
// StreamDeck XL: 768px 384px
namespace StreamDeckify
{
public partial class ResizeImages : Form
{
public Image imageOverlay;
public Image imageBackground;
public Image selectedFile;
public ResizeImages()
{
InitializeComponent();
comboBox1.SelectedIndex = 1;
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
MinimizeBox = false;
StartPosition = FormStartPosition.CenterScreen;
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Image imageOverlay;
switch (comboBox1.SelectedIndex)
{
case 0:
imageOverlay = Image.FromFile("C:\\Users\\unaii\\Desktop\\StreamDeckify\\StreamDeckMini.png");
pictureBox3.Image = imageOverlay;
pictureBox3.Refresh();
break;
case 1:
imageOverlay = Image.FromFile("C:\\Users\\unaii\\Desktop\\StreamDeckify\\StreamDeck.png");
pictureBox3.Image = imageOverlay;
pictureBox3.Refresh();
break;
case 2:
imageOverlay = Image.FromFile("C:\\Users\\unaii\\Desktop\\StreamDeckify\\StreamDeckPlus.png");
pictureBox3.Image = imageOverlay;
pictureBox3.Refresh();
break;
case 3:
imageOverlay = Image.FromFile("C:\\Users\\unaii\\Desktop\\StreamDeckify\\StreamDeckXL.png");
pictureBox3.Image = imageOverlay;
pictureBox3.Refresh();
break;
}
}
public void browse_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
openFileDialog1.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
openFileDialog1.Title = "Open image";
string selectedFile = System.IO.Path.GetFileName(openFileDialog1.FileName); ;
label4.Text = selectedFile;
int streamWidth = 310;
int streamHeight = 185;
int streamGap1 = 30;
int streamGap2 = 30;
switch (comboBox1.SelectedIndex)
{
case 0:
imageOverlay = Image.FromFile("C:\\Users\\unaii\\Desktop\\StreamDeckify\\StreamDeckMini.png");
streamWidth = 250;
streamHeight = 175;
streamGap1 = 60;
streamGap2 = 75;
break;
case 1:
imageOverlay = Image.FromFile("C:\\Users\\unaii\\Desktop\\StreamDeckify\\StreamDeck.png");
streamWidth = 330;
streamHeight = 175;
streamGap1 = 30;
streamGap2 = 55;
break;
case 2:
imageOverlay = Image.FromFile("C:\\Users\\unaii\\Desktop\\StreamDeckify\\StreamDeckPlus.png");
streamWidth = 240;
streamHeight = 170;
streamGap1 = 65;
streamGap2 = 30;
break;
case 3:
imageOverlay = Image.FromFile("C:\\Users\\unaii\\Desktop\\StreamDeckify\\StreamDeckXL.png");
streamWidth = 330;
streamHeight = 175;
streamGap1 = 30;
streamGap2 = 45;
break;
}
Image imageBackground = Image.FromFile(openFileDialog1.FileName);
int overlayX = imageBackground.Width; // la posición X de la capa de superposición en la imagen final
int overlayY = imageBackground.Height; // la posición Y de la capa de superposición en la imagen final
Image img = new Bitmap(380, 273); // creas la imagen final con el tamaño de la capa de superposición
using (Graphics gr = Graphics.FromImage(img))
{
gr.DrawImage(imageBackground, streamGap1, streamGap2, streamWidth, streamHeight);// dibujas la imagen de fondo en la posición correcta según la capa de superposición
gr.DrawImage(imageOverlay, 0, 0, 380, 273); // dibujas la capa de superposición en la posición (0, 0)
gr.Flush(); // para asegurarte de que los cambios se han aplicado correctamente
imageOverlay.Dispose(); // liberas los recursos de la capa de superposición
}
pictureBox3.Image = img;
pictureBox3.Refresh();
}
private void pictureBox3_Click(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
public void button1_Click(object sender, EventArgs e)
{
int streamWidth = 0;
int streamHeight = 0;
switch (comboBox1.SelectedIndex)
{
case 0: // StreamDeck Mini: 216px 144px
streamWidth = 216;
streamHeight = 144;
break;
case 1: // StreamDeck MK2: 360px 216px
streamWidth = 360;
streamHeight = 216;
break;
case 2: // StreamDeck +: 360px 144px
streamWidth = 360;
streamHeight = 144;
break;
case 3: // StreamDeck XL: 768px 384px
streamWidth = 768;
streamHeight = 384;
break;
}
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
saveFileDialog1.Title = "Guardar imagen";
string selectedFile = System.IO.Path.GetFileName(saveFileDialog1.FileName); ;
// Check if the OpenFileDialog has a file name
if (openFileDialog1.FileName != "")
{
// Set the initial directory and file name for the SaveFileDialog
saveFileDialog1.InitialDirectory = openFileDialog1.InitialDirectory;
saveFileDialog1.FileName = openFileDialog1.FileName;
}
// Show the SaveFileDialog to the user
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
// Redimensiona la imagen original
Image imagenOriginal = Image.FromFile(openFileDialog1.FileName);
Image imagenRedimensionada = imagenOriginal.GetThumbnailImage(streamWidth, streamHeight, null, IntPtr.Zero);
imagenRedimensionada.Save(saveFileDialog1.FileName);
label6.Text = "Done! Your new wallwaper is on: \n" + saveFileDialog1.FileName;
}
}
private void ResizeImages_Load(object sender, EventArgs e)
{
}
private void label6_Click(object sender, EventArgs e)
{
}
private void label5_Click(object sender, EventArgs e)
{
}
}
}