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:
| using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Windows; using System.Windows.Media; using Image = System.Drawing.Image; using MessageBox = System.Windows.MessageBox; using Rectangle = System.Drawing.Rectangle; namespace Convertilon { public partial class MainWindow { public MainWindow() { InitializeComponent(); } private void Changilon(object sender, RoutedEventArgs e) { var b = new ImageSourceConverter(); var bild1 = Image.FromFile(file1.Text); var bild2 = SetImgOpacity(new Bitmap(file2.Text), (float)slider1.Value); var scaling = Math.Round(slider1.Value); var pos = 0; int xpos; int ypos; if (rbLinks.IsChecked == true) pos = 1; if (rbObenLinks.IsChecked == true) pos = 2; if (rbOben.IsChecked == true) pos = 3; if (rbObenRechts.IsChecked == true) pos = 4; if (rbRechts.IsChecked == true) pos = 5; if (rbUntenRechts.IsChecked == true) pos = 6; if (rbUnten.IsChecked == true) pos = 7; if (rbUntenLinks.IsChecked == true) pos = 8; switch (pos) { case 1: xpos = 0; ypos = (int)Math.Round(bild1.Height/2d) - (int)Math.Round(bild2.Height/(2*scaling)); break; case 2: xpos = 0; ypos = 0; break; case 3: xpos = (int) Math.Round(bild1.Width/2d) - (int) Math.Round(bild2.Width/(2*scaling)); ypos = 0; break; case 4: xpos = bild1.Width - (int) Math.Round(bild2.Width/scaling); ypos = 0; break; case 5: xpos = bild1.Width - (int) Math.Round(bild2.Width/scaling); ypos = (int) Math.Round(bild1.Height/2d) - (int) Math.Round(bild2.Height/(2*scaling)); break; case 6: xpos = bild1.Width - (int) Math.Round(bild2.Width/scaling); ypos = bild1.Height - (int) Math.Round(bild2.Height/scaling); break; case 7: xpos = (int) Math.Round(bild1.Width/2d) - (int) Math.Round(bild2.Width/(2*scaling)); ypos = bild1.Height - (int) Math.Round(bild2.Height/scaling); break; case 8: xpos = 0; ypos = bild1.Height - (int) Math.Round(bild2.Height/scaling); break; default: xpos = 0; ypos = 0; break; } var cmxPic = new ColorMatrix { Matrix33 = 1 }; ImageAttributes iaPic = new ImageAttributes(); iaPic.SetColorMatrix(cmxPic, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); var g = Graphics.FromImage(bild1); g.DrawImage(bild2, new Rectangle(xpos, ypos, (int)Math.Round(bild2.Width/scaling), (int)Math.Round(bild2.Height/scaling)), 0, 0, bild2.Width, bild2.Height, GraphicsUnit.Pixel, iaPic); try { var name1 = genName(); bild1.Save(name1 + ".jpg"); var bild = b.ConvertFromString(name1 + ".jpg"); image3.Source = (ImageSource)bild; bild1.Dispose(); } catch { MessageBox.Show("Zoooonk"); } finally { bild1.Dispose(); } } public string genName() { var b = new Random(); var alphabet = new string[26] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; var name = ""; for (var i = 0; i < 5; i++) { var c = b.Next(0, 25); name = name + alphabet[c]; } return name; } private void LeOpen1(object sender, RoutedEventArgs e) { var dlg = new Microsoft.Win32.OpenFileDialog { FileName = "", DefaultExt = ".png", Filter = "PNG-Images (.png)|*.png|JPEG-Images (.jpg)|*.jpg|Bitmapscheisse (.bmp)|*.bmp|All files (*.*)|*.*" }; bool? result = dlg.ShowDialog(); if (result == true) { string filename = dlg.FileName; } if (!string.IsNullOrEmpty(dlg.FileName)) { file1.Text = dlg.FileName; var sr = new StreamReader(dlg.FileName); sr.Close(); var b = new ImageSourceConverter(); var f = b.ConvertFromString(dlg.FileName); image1.Source = (ImageSource) f; } } private void LeOpen2(object sender, RoutedEventArgs e) { var dlg = new Microsoft.Win32.OpenFileDialog { FileName = "", DefaultExt = ".png", Filter = "PNG-Images (.png)|*.png|JPEG-Images (.jpg)|*.jpg|Bitmapscheisse (.bmp)|*.bmp|All files (*.*)|*.*" }; bool? result = dlg.ShowDialog(); if (result == true) { string filename = dlg.FileName; } if (!string.IsNullOrEmpty(dlg.FileName)) { file2.Text = dlg.FileName; var sr = new StreamReader(dlg.FileName); sr.Close(); var b = new ImageSourceConverter(); var f = b.ConvertFromString(dlg.FileName); image2.Source = (ImageSource) f; } } } } |