This repository was archived by the owner on Mar 21, 2025. It is now read-only.
forked from pejamas/Poster-Overlay-GUI
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPosterOverlay.cs
More file actions
431 lines (389 loc) · 16.1 KB
/
Copy pathPosterOverlay.cs
File metadata and controls
431 lines (389 loc) · 16.1 KB
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
namespace PosterOverlay
{
public partial class PosterOverlay : Form
{
private PictureBox pbResultImage;
private ComboBox cboOverlayImage;
private Image baseImage;
private object overlayImagePath;
private string currentFileandPath;
public PosterOverlay()
{
InitializeComponent();
ConfigureForm();
}
private void ConfigureForm()
{
SetFormAppearance();
CreateOverlayImageComboBox();
CreateBaseImageButton();
CreateResultImagePictureBox();
CreateSaveAsImageButton();
CreateSaveImageButton();
CreateResetButton();
}
private void SetFormAppearance()
{
this.BackColor = Color.DarkGray;
}
private void CreateOverlayImageComboBox()
{
cboOverlayImage = new ComboBox();
cboOverlayImage.Items.AddRange(new object[] {
"UHDBD with HDR and Atmos",
"UHDBD with DV and Atmos",
"UHDBD with HDR and DTS",
"UHDBD with DV and DTS",
"UHDBD with DV and IMAX",
"UHDBD with DV",
"UHDBD with HDR",
"UHDBD with HDR and IMAX",
"UHDBD with HDR10+",
"UHDBD with HDR10+ and IMAX",
"UHDBD with IMAX",
"UHDBD",
"BD with DV and IMAX",
"BD with DV",
"BD with HDR",
"BD with HDR and IMAX",
"BD with HDR10+",
"BD with HDR10+ and IMAX",
"BD with IMAX",
"BD 3D",
"BD 3D with IMAX",
"BD",
"DTheater"
});
cboOverlayImage.Size = new Size(160, 23);
cboOverlayImage.Location = new Point(193, 17);
cboOverlayImage.DropDownStyle = ComboBoxStyle.DropDownList;
cboOverlayImage.BackColor = Color.LightGray;
cboOverlayImage.ForeColor = Color.Black;
cboOverlayImage.Font = new Font("Arial", 10, FontStyle.Regular);
cboOverlayImage.FlatStyle = FlatStyle.Flat;
cboOverlayImage.Text = "Choose Overlay";
cboOverlayImage.SelectedIndex = 0;
Controls.Add(cboOverlayImage);
cboOverlayImage.SelectedIndexChanged += new EventHandler(cboOverlayImage_SelectedIndexChanged);
}
private void CreateBaseImageButton()
{
Button btnBaseImage = new Button
{
Text = "Select Poster",
Size = cboOverlayImage.Size,
Location = new Point(23, 17),
BackColor = Color.LightGray,
ForeColor = Color.Black,
Font = new Font("Arial", 10, FontStyle.Regular),
FlatStyle = FlatStyle.Flat
};
btnBaseImage.Click += new EventHandler(btnBaseImage_Click);
Controls.Add(btnBaseImage);
}
private void CreateResultImagePictureBox()
{
pbResultImage = new PictureBox
{
SizeMode = PictureBoxSizeMode.Zoom,
Size = new Size(502, 755),
Location = new Point(23, 60),
BorderStyle = BorderStyle.FixedSingle
};
Controls.Add(pbResultImage);
}
private void CreateSaveAsImageButton()
{
Button btnSaveAsImage = new Button
{
Text = "Save as...",
Size = cboOverlayImage.Size,
Location = new Point(365, 842),
BackColor = Color.LightGray,
ForeColor = Color.Black,
Font = new Font("Arial", 10, FontStyle.Regular),
FlatStyle = FlatStyle.Flat
};
btnSaveAsImage.Click += new EventHandler(btnSaveAsImage_Click);
Controls.Add(btnSaveAsImage);
}
private void CreateSaveImageButton()
{
Button btnSaveImage = new Button
{
Text = "Save",
Size = cboOverlayImage.Size,
Location = new Point(365, 17),
BackColor = Color.LightGray,
ForeColor = Color.Black,
Font = new Font("Arial", 10, FontStyle.Regular),
FlatStyle = FlatStyle.Flat
};
btnSaveImage.Click += new EventHandler(btnSaveImage_Click);
Controls.Add(btnSaveImage);
}
private void CreateResetButton()
{
Button btnReset = new Button
{
Text = "Reset",
Size = cboOverlayImage.Size,
Location = new Point(190, 842),
BackColor = Color.Red,
ForeColor = Color.White,
Font = new Font("Arial", 10, FontStyle.Regular),
FlatStyle = FlatStyle.Flat
};
btnReset.Click += new EventHandler(btnReset_Click);
Controls.Add(btnReset);
}
private void pbResultImage_Paint(object sender, PaintEventArgs e)
{
Pen borderPen = new Pen(Color.White, 10);
e.Graphics.DrawRectangle(borderPen, new Rectangle(pbResultImage.Location, pbResultImage.Size));
}
private void btnReset_Click(object sender, EventArgs e)
{
cboOverlayImage.SelectedIndex = -1;
pbResultImage.Image = null;
//Clear the base image so overwriting it is possible
baseImage.Dispose();
}
private void btnBaseImage_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog
{
Filter = "Image Files (*.jpg;*.png)|*.jpg;*.png|All files (*.*)|*.*"
};
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//Load the base image using method
LoadBaseImage(openFileDialog.FileName);
//Ensure we save the current filename and path so we can do quick overwrites later
currentFileandPath = openFileDialog.FileName;
}
}
private void LoadBaseImage(string filenameAndPath)
{
baseImage = Image.FromFile(filenameAndPath);
int maxWidth = 1000;
int maxHeight = 1500;
double ratioX = (double)maxWidth / baseImage.Width;
double ratioY = (double)maxHeight / baseImage.Height;
double ratio = Math.Min(ratioX, ratioY);
int newWidth = (int)(baseImage.Width * ratio);
int newHeight = (int)(baseImage.Height * ratio);
Bitmap bitmap = new Bitmap(baseImage, newWidth, newHeight);
pbResultImage.Image = bitmap;
//Select whatever Overlay is currently selected in the dropdown list as the one to apply when base image is loaded
SelectOverlay();
}
private void SelectOverlay()
{
string overlayFilename = "";
switch (cboOverlayImage.SelectedIndex)
{
case 0:
overlayFilename = @"OverlayImages\UHDBD with HDR and Atmos.png";
break;
case 1:
overlayFilename = @"OverlayImages\UHDBD with DV and Atmos.png";
break;
case 2:
overlayFilename = @"OverlayImages\UHDBD with HDR and DTS.png";
break;
case 3:
overlayFilename = @"OverlayImages\UHDBD with DV and DTS.png";
break;
case 4:
overlayFilename = @"OverlayImages\UHDBD with DV and Imax.png";
break;
case 5:
overlayFilename = @"OverlayImages\UHDBD with DV.png";
break;
case 6:
overlayFilename = @"OverlayImages\UHDBD with HDR.png";
break;
case 7:
overlayFilename = @"OverlayImages\UHDBD with HDR and Imax.png";
break;
case 8:
overlayFilename = @"OverlayImages\UHDBD with HDR10+.png";
break;
case 9:
overlayFilename = @"OverlayImages\UHDBD with HDR10+ and Imax.png";
break;
case 10:
overlayFilename = @"OverlayImages\UHDBD with Imax.png";
break;
case 11:
overlayFilename = @"OverlayImages\UHDBD.png";
break;
case 12:
overlayFilename = @"OverlayImages\BD with DV and Imax.png";
break;
case 13:
overlayFilename = @"OverlayImages\BD with DV.png";
break;
case 14:
overlayFilename = @"OverlayImages\BD with HDR.png";
break;
case 15:
overlayFilename = @"OverlayImages\BD with HDR and Imax.png";
break;
case 16:
overlayFilename = @"OverlayImages\BD with HDR10+.png";
break;
case 17:
overlayFilename = @"OverlayImages\BD with HDR10+ and Imax.png";
break;
case 18:
overlayFilename = @"OverlayImages\BD with Imax.png";
break;
case 19:
overlayFilename = @"OverlayImages\BD 3D.png";
break;
case 20:
overlayFilename = @"OverlayImages\BD 3D with IMAX.png";
break;
case 21:
overlayFilename = @"OverlayImages\BD.png";
break;
case 22:
overlayFilename = @"OverlayImages\DTheater.png";
break;
}
ApplyOverlay(overlayFilename);
}
private void cboOverlayImage_SelectedIndexChanged(object sender, EventArgs e)
{
SelectOverlay();
}
private void ApplyOverlay(string overlayFilename)
{
if (overlayFilename != "")
{
overlayImagePath = overlayFilename;
Bitmap baseBitmap = pbResultImage.Image != null ? new Bitmap(pbResultImage.Image) : new Bitmap(1000, 1500);
if (baseImage != null)
{
int maxWidth = 1000;
int maxHeight = 1500;
double ratioX = (double)maxWidth / baseImage.Width;
double ratioY = (double)maxHeight / baseImage.Height;
double ratio = Math.Min(ratioX, ratioY);
int resizedWidth = (int)(baseImage.Width * ratio);
int resizedHeight = (int)(baseImage.Height * ratio);
Bitmap resizedBitmap = new Bitmap(resizedWidth, resizedHeight);
using (Graphics graphics = Graphics.FromImage(resizedBitmap))
{
graphics.DrawImage(baseImage, 0, 0, resizedWidth, resizedHeight);
}
baseBitmap = resizedBitmap;
}
Bitmap overlayBitmap = new Bitmap(overlayFilename);
float scaleX = (float)baseBitmap.Width / overlayBitmap.Width;
float scaleY = (float)baseBitmap.Height / overlayBitmap.Height;
float scale = Math.Min(scaleX, scaleY);
int newWidth = (int)(overlayBitmap.Width * scale);
int newHeight = (int)(overlayBitmap.Height * scale);
Bitmap resizedOverlayBitmap = new Bitmap(newWidth, newHeight);
using (Graphics graphics = Graphics.FromImage(resizedOverlayBitmap))
{
graphics.DrawImage(overlayBitmap, 0, 0, newWidth, newHeight);
}
Bitmap resultBitmap = new Bitmap(baseBitmap.Width, baseBitmap.Height);
using (Graphics graphics = Graphics.FromImage(resultBitmap))
{
graphics.DrawImage(baseBitmap, 0, 0);
graphics.DrawImage(resizedOverlayBitmap, 0, 0);
}
pbResultImage.Image = resultBitmap;
}
}
private void btnSaveAsImage_Click(object sender, EventArgs e)
{
if (baseImage == null || overlayImagePath == null)
{
MessageBox.Show("Please select a base image and overlay image.", "Error");
return;
}
Image overlayImage = Image.FromFile((string)overlayImagePath);
int targetWidth = 1000;
int targetHeight = 1500;
Bitmap resultBitmap = new Bitmap(targetWidth, targetHeight, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(resultBitmap))
{
g.DrawImage(baseImage, 0, 0, targetWidth, targetHeight);
g.DrawImage(overlayImage, 0, 0, targetWidth, targetHeight);
}
pbResultImage.Image = resultBitmap;
SaveFileDialog saveFileDialog = new SaveFileDialog
{
Filter = "JPEG Image (*.jpg)|*.jpg|PNG Image (*.png)|*.png",
DefaultExt = "jpg" // Default extension
};
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
// Clear the base image to allow overwriting
baseImage.Dispose();
// Save the new image in the desired size
resultBitmap.Save(saveFileDialog.FileName, ImageFormat.Jpeg);
// Reload the now updated base image to continue working with it if needed
LoadBaseImage(saveFileDialog.FileName);
}
}
private void btnSaveImage_Click(object sender, EventArgs e)
{
if (baseImage == null || overlayImagePath == null)
{
MessageBox.Show("Please select a base image and overlay image.", "Error");
return;
}
Image overlayImage = Image.FromFile((string)overlayImagePath);
// Zielgröße für das Bild festlegen
int targetWidth = 1000;
int targetHeight = 1500;
// Erstellen eines neuen Bitmaps mit der Zielgröße
Bitmap resultBitmap = new Bitmap(targetWidth, targetHeight, PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(resultBitmap))
{
// Basisbild und Overlay-Bild skalieren und zeichnen
g.DrawImage(baseImage, 0, 0, targetWidth, targetHeight);
g.DrawImage(overlayImage, 0, 0, targetWidth, targetHeight);
}
pbResultImage.Image = resultBitmap;
// Basisbild freigeben, um das Überschreiben zu ermöglichen
baseImage.Dispose();
// Neues Bild im aktuellen Pfad und Ursprungsformat speichern
string extension = Path.GetExtension(currentFileandPath).ToLower();
ImageFormat imageFormat;
// Format basierend auf Dateierweiterung bestimmen
switch (extension)
{
case ".png":
imageFormat = ImageFormat.Png;
break;
case ".jpg":
case ".jpeg":
imageFormat = ImageFormat.Jpeg;
break;
default:
MessageBox.Show("Unsupported file format.", "Error");
return;
}
resultBitmap.Save(currentFileandPath, imageFormat);
// Aktualisiertes Basisbild neu laden, falls es weiterverwendet werden soll
LoadBaseImage(currentFileandPath);
}
private void PosterOverlay_Load(object sender, EventArgs e)
{
}
}
}