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: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584:
| using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Data; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Drawing; using System.Drawing.Imaging; using Microsoft.Win32;
namespace Main {
public partial class Format_1920x720 : Window { string filename;
int[] Pixelpos_1 = new int[2]; int[] Pixelpos_2 = new int[2]; int[] Pixelpos_3 = new int[2]; int[] Pixelpos_4 = new int[2]; int[] Pixelpos_5 = new int[2]; int[] Pixelpos_6 = new int[2]; int[] Pixelpos_7 = new int[2]; int[] Pixelpos_8 = new int[2]; int[] Pixelpos_9 = new int[2]; int[] Pixelpos_10 = new int[2]; int[] Pixelpos_11 = new int[2]; int[] Pixelpos_12 = new int[2];
int[] RGB_Pixel = new int[12];
int bildgeladen = 0;
int pixpos = 0;
int bildZaehler = 0;
int einmalspeichern = 0;
public Format_1920x720() { InitializeComponent(); }
private void Button_Click(object sender, RoutedEventArgs e) { ImageFileHelper ifh = new ImageFileHelper(); BildLaden.Source = new BitmapImage(ifh.Open()); bildgeladen = 1; lab1.Visibility = Visibility.Hidden; lab2.Visibility = Visibility.Hidden; oeffnenButton.Visibility = Visibility.Hidden; }
private void AddPicButton_Click(object sender, RoutedEventArgs e) { if (bildgeladen == 1) { if(!( String.IsNullOrEmpty(RGB1.Text) || String.IsNullOrEmpty(RGB1.Text) || String.IsNullOrEmpty(RGB2.Text) || String.IsNullOrEmpty(RGB3.Text) || String.IsNullOrEmpty(RGB4.Text) || String.IsNullOrEmpty(RGB5.Text) || String.IsNullOrEmpty(RGB6.Text) || String.IsNullOrEmpty(RGB7.Text) || String.IsNullOrEmpty(RGB8.Text) || String.IsNullOrEmpty(RGB10.Text) || String.IsNullOrEmpty(RGB11.Text) || String.IsNullOrEmpty(RGB12.Text) )) {
RGB_Pixel[0] = Convert.ToInt32(RGB1.Text); RGB_Pixel[1] = Convert.ToInt32(RGB2.Text); RGB_Pixel[2] = Convert.ToInt32(RGB3.Text); RGB_Pixel[3] = Convert.ToInt32(RGB4.Text); RGB_Pixel[4] = Convert.ToInt32(RGB5.Text); RGB_Pixel[5] = Convert.ToInt32(RGB6.Text); RGB_Pixel[6] = Convert.ToInt32(RGB7.Text); RGB_Pixel[7] = Convert.ToInt32(RGB8.Text); RGB_Pixel[8] = Convert.ToInt32(RGB9.Text); RGB_Pixel[9] = Convert.ToInt32(RGB10.Text); RGB_Pixel[10] = Convert.ToInt32(RGB11.Text); RGB_Pixel[11] = Convert.ToInt32(RGB12.Text);
ImageFileHelper ifh = new ImageFileHelper(); ifh.Save(BildLaden.Source as BitmapSource); bildZaehler++; BildLaden.Source = new BitmapImage(new Uri("C:\\Users\\sahifat\\Desktop\\logo1.png"));
} else { System.Windows.MessageBox.Show("Bitte ausnahmslos alle 12 Pixelfarbwerte angeben!"); } } else { System.Windows.MessageBox.Show("Bitte Bild zuerst laden!"); }
}
private void VidButton_Click(object sender, RoutedEventArgs e) { }
private void Button_Click_1(object sender, RoutedEventArgs e) { if ( !( String.IsNullOrEmpty(Pixel11.Text) || String.IsNullOrEmpty(Pixel12.Text) || String.IsNullOrEmpty(Pixel21.Text) || String.IsNullOrEmpty(Pixel22.Text) || String.IsNullOrEmpty(Pixel31.Text) || String.IsNullOrEmpty(Pixel32.Text) || String.IsNullOrEmpty(Pixel41.Text) || String.IsNullOrEmpty(Pixel42.Text) || String.IsNullOrEmpty(Pixel51.Text) || String.IsNullOrEmpty(Pixel52.Text) || String.IsNullOrEmpty(Pixel61.Text) || String.IsNullOrEmpty(Pixel62.Text) || String.IsNullOrEmpty(Pixel71.Text) || String.IsNullOrEmpty(Pixel72.Text) || String.IsNullOrEmpty(Pixel81.Text) || String.IsNullOrEmpty(Pixel82.Text) || String.IsNullOrEmpty(Pixel91.Text) || String.IsNullOrEmpty(Pixel92.Text) || String.IsNullOrEmpty(Pixel101.Text) || String.IsNullOrEmpty(Pixel102.Text) || String.IsNullOrEmpty(Pixel111.Text) || String.IsNullOrEmpty(Pixel112.Text) || String.IsNullOrEmpty(Pixel121.Text) || String.IsNullOrEmpty(Pixel122.Text) )) { Pixelpos_1[0] = Convert.ToInt32(Pixel11.Text); Pixelpos_1[1] = Convert.ToInt32(Pixel12.Text);
Pixelpos_2[0] = Convert.ToInt32(Pixel21.Text); Pixelpos_2[1] = Convert.ToInt32(Pixel22.Text);
Pixelpos_3[0] = Convert.ToInt32(Pixel31.Text); Pixelpos_3[1] = Convert.ToInt32(Pixel32.Text);
Pixelpos_4[0] = Convert.ToInt32(Pixel41.Text); Pixelpos_4[1] = Convert.ToInt32(Pixel42.Text);
Pixelpos_5[0] = Convert.ToInt32(Pixel51.Text); Pixelpos_5[1] = Convert.ToInt32(Pixel52.Text);
Pixelpos_6[0] = Convert.ToInt32(Pixel61.Text); Pixelpos_6[1] = Convert.ToInt32(Pixel62.Text);
Pixelpos_7[0] = Convert.ToInt32(Pixel71.Text); Pixelpos_7[1] = Convert.ToInt32(Pixel72.Text);
Pixelpos_8[0] = Convert.ToInt32(Pixel81.Text); Pixelpos_8[1] = Convert.ToInt32(Pixel82.Text);
Pixelpos_9[0] = Convert.ToInt32(Pixel91.Text); Pixelpos_9[1] = Convert.ToInt32(Pixel92.Text);
Pixelpos_10[0] = Convert.ToInt32(Pixel101.Text); Pixelpos_10[1] = Convert.ToInt32(Pixel102.Text);
Pixelpos_11[0] = Convert.ToInt32(Pixel111.Text); Pixelpos_11[1] = Convert.ToInt32(Pixel112.Text);
Pixelpos_12[0] = Convert.ToInt32(Pixel121.Text); Pixelpos_12[1] = Convert.ToInt32(Pixel122.Text);
System.Windows.MessageBox.Show("Sie haben folgende Pixel anvisiert:" + Environment.NewLine + Environment.NewLine + " Pixel 01: P01[" + Convert.ToString(Pixelpos_1[0]) + "|" + Convert.ToString(Pixelpos_1[1]) + "]" + Environment.NewLine + " Pixel 02: P02[" + Convert.ToString(Pixelpos_2[0]) + "|" + Convert.ToString(Pixelpos_2[1]) + "]" + Environment.NewLine + " Pixel 03: P03[" + Convert.ToString(Pixelpos_3[0]) + "|" + Convert.ToString(Pixelpos_3[1]) + "]" + Environment.NewLine + " Pixel 04: P04[" + Convert.ToString(Pixelpos_4[0]) + "|" + Convert.ToString(Pixelpos_4[1]) + "]" + Environment.NewLine + " Pixel 05: P05[" + Convert.ToString(Pixelpos_5[0]) + "|" + Convert.ToString(Pixelpos_5[1]) + "]" + Environment.NewLine + " Pixel 06: P06[" + Convert.ToString(Pixelpos_6[0]) + "|" + Convert.ToString(Pixelpos_6[1]) + "]" + Environment.NewLine + " Pixel 07: P07[" + Convert.ToString(Pixelpos_7[0]) + "|" + Convert.ToString(Pixelpos_7[1]) + "]" + Environment.NewLine + " Pixel 08: P08[" + Convert.ToString(Pixelpos_8[0]) + "|" + Convert.ToString(Pixelpos_8[1]) + "]" + Environment.NewLine + " Pixel 09: P09[" + Convert.ToString(Pixelpos_9[0]) + "|" + Convert.ToString(Pixelpos_9[1]) + "]" + Environment.NewLine + " Pixel 10: P10[" + Convert.ToString(Pixelpos_10[0]) + "|" + Convert.ToString(Pixelpos_10[1]) + "]" + Environment.NewLine + " Pixel 11: P11[" + Convert.ToString(Pixelpos_11[0]) + "|" + Convert.ToString(Pixelpos_11[1]) + "]" + Environment.NewLine + " Pixel 12: P12[" + Convert.ToString(Pixelpos_12[0]) + "|" + Convert.ToString(Pixelpos_12[1]) + "]" + Environment.NewLine ) ;
pixpos = 1; } else System.Windows.MessageBox.Show("Bitte alle 12 Pixelpositionen angeben!"); } }
public sealed class ImageFileHelper { public ImageFileHelper() { this.AllowedExtensions = new List<ImageFileExtensions>(); }
public string InitialDirectory { get; set; } public string InitialFileName { get; set; } public List<ImageFileExtensions> AllowedExtensions { get; set; } public BitmapMetadata Metadata { get; set; } public BitmapPalette Palette { get; set; } public BitmapSource Thumbnail { get; set; }
public Uri Open() { return Open(GetOFD(false)); }
public IEnumerable<Uri> OpenMultiple() { return OpenMultiple(GetOFD(true)); }
public bool Save(BitmapSource image) { return Save(image, GetSFD()); } public string Save() {
var sfd = GetSFD();
if (sfd.ShowDialog() == true) return sfd.FileName; else return null; }
public event EventHandler<QualitiyRequiredEventArgs> QualitiyRequired;
Uri Open(OpenFileDialog ofd) { if (ofd.ShowDialog() == true) { return new Uri(ofd.FileName, UriKind.RelativeOrAbsolute); } else return null; } IEnumerable<Uri> OpenMultiple(OpenFileDialog ofd) { if (ofd.ShowDialog() == true) { foreach (var file in ofd.FileNames) yield return new Uri(ofd.FileName, UriKind.RelativeOrAbsolute); } } bool Save(BitmapSource image, SaveFileDialog sfd) { if (sfd.ShowDialog() == true) { var enc = GetEncoder(image, sfd); using (Stream sw = new FileStream(sfd.FileName, FileMode.Create)) { enc.Save(sw); } return true; } return false; }
private BitmapEncoder GetEncoder(BitmapSource image, SaveFileDialog sfd) { BitmapEncoder enc = null; switch (sfd.FileName.ToLower().Split('.').Last()) { case "png": enc = new PngBitmapEncoder(); break; case "jpg": case "jpeg": enc = new JpegBitmapEncoder() { QualityLevel = GetQualitiy(ImageFileExtensions.JPG),
}; break; case "bmp": case "dif": enc = new BmpBitmapEncoder(); break; case "tif": case "tiff": enc = new TiffBitmapEncoder(); break; case "gif": enc = new GifBitmapEncoder(); break; case "wmp": enc = new WmpBitmapEncoder() { QualityLevel = GetQualitiy(ImageFileExtensions.WMP), }; break; default: return null; } if (this.Thumbnail != null) enc.Thumbnail = this.Thumbnail; if (this.Palette != null) enc.Palette = this.Palette; if (this.Metadata != null) enc.Metadata = this.Metadata; enc.Frames.Add(BitmapFrame.Create(image));
return enc; }
private byte GetQualitiy(ImageFileExtensions imageType) { var evt = this.QualitiyRequired; if (evt != null) { QualitiyRequiredEventArgs e = null; switch (imageType) { case ImageFileExtensions.JPG: e = new QualitiyRequiredEventArgs(1, 100, 94, imageType); break; case ImageFileExtensions.WMP: e = new QualitiyRequiredEventArgs(1, 255, 1, imageType); break; default: throw new ArgumentOutOfRangeException(); } evt(this, e); return e.Quality; } return 94; }
#region create FileDialog instances
OpenFileDialog GetOFD(bool multiSelect) { return new OpenFileDialog() { Filter = GetFilter(this.AllowedExtensions), InitialDirectory = this.InitialDirectory, Multiselect = multiSelect, FileName = this.InitialFileName, }; } SaveFileDialog GetSFD() { return new SaveFileDialog() { Filter = GetFilter(this.AllowedExtensions), InitialDirectory = this.InitialDirectory, FileName = this.InitialFileName, }; }
string GetFilter(List<ImageFileExtensions> allowedExtensions) { StringBuilder filterBuilder = new StringBuilder(); if (allowedExtensions == null || allowedExtensions.Contains(ImageFileExtensions.PNG)) AppendFilter(filterBuilder, ImageFileExtensions.PNG); if (allowedExtensions == null || allowedExtensions.Contains(ImageFileExtensions.JPG)) AppendFilter(filterBuilder, ImageFileExtensions.JPG); if (allowedExtensions == null || allowedExtensions.Contains(ImageFileExtensions.BMP)) AppendFilter(filterBuilder, ImageFileExtensions.BMP); if (allowedExtensions == null || allowedExtensions.Contains(ImageFileExtensions.TIFF)) AppendFilter(filterBuilder, ImageFileExtensions.TIFF); if (allowedExtensions == null || allowedExtensions.Contains(ImageFileExtensions.GIF)) AppendFilter(filterBuilder, ImageFileExtensions.GIF); if (allowedExtensions == null || allowedExtensions.Contains(ImageFileExtensions.All)) AppendFilter(filterBuilder, ImageFileExtensions.All); return filterBuilder.ToString(); } void AppendFilter(StringBuilder filterBuilder, ImageFileExtensions extension) { if (filterBuilder.Length != 0) filterBuilder.Append("|");
switch (extension) { case ImageFileExtensions.PNG: filterBuilder.Append("Portable Network Graphic (*.PNG)|*.png"); break; case ImageFileExtensions.JPG: filterBuilder.Append("JPEG (*.JPEG;*.JPG)|*.jpeg;*.jpg"); break; case ImageFileExtensions.BMP: filterBuilder.Append("Bitmap (*.BMP)|*.bmp"); break; case ImageFileExtensions.TIFF: filterBuilder.Append("TIFF (*.TIFF;*.TIF)|*.tiff;*.tif"); break; case ImageFileExtensions.GIF: filterBuilder.Append("GIF (*.GIF)|*.gif"); break; case ImageFileExtensions.WMP: filterBuilder.Append("Windows Media Photo (*.WMP)|*.wmp"); break; case ImageFileExtensions.All: filterBuilder.Append("All Files|*.*"); break; } }
#endregion }
public enum ImageFileExtensions { PNG, JPG, BMP, TIFF, GIF, WMP, All, }
public sealed class QualitiyRequiredEventArgs : EventArgs { public byte Quality { get; set; } public byte Minimum { get; private set; } public byte Maximum { get; private set; } public ImageFileExtensions Type { get; set; }
public QualitiyRequiredEventArgs(byte minimum, byte maximum, byte quality, ImageFileExtensions type) { this.Minimum = minimum; this.Maximum = maximum; this.Quality = quality; this.Type = type; } }
} |