//background image convertation worker private void worker_DoWork(object sender, DoWorkEventArgs e) { worker.ReportProgress(3); AdaptivePaletteConverter apl = new AdaptivePaletteConverter(originalBitmap); worker.ReportProgress(7); AdaptivePaletteReader apr = new AdaptivePaletteReader(); worker.ReportProgress(14); adaptivePaletteData = apl.GetImageData(); worker.ReportProgress(50); adaptivePaletteBmp = apr.convertDataToBitmap(adaptivePaletteData); worker.ReportProgress(70); paletteImgData = p.GetImageData(originalBitmap); worker.ReportProgress(82); fixedPaletteBmp = p.convertDataToBitmap(paletteImgData); worker.ReportProgress(100); }
private void Open_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { //cancel converting if (worker.IsBusy == true && worker.WorkerSupportsCancellation == true) { worker.CancelAsync(); } //default state of WPF elements Convert_Button.IsEnabled = false; ConversionBox.Visibility = Visibility.Hidden; //open 3-3-2 format image if (System.IO.Path.GetExtension(openFileDialog.FileName) == ".lol") { paletteImgData = File.ReadAllBytes(openFileDialog.FileName); originalBitmap = p.convertDataToBitmap(paletteImgData); } //open adaptive palette image else if (System.IO.Path.GetExtension(openFileDialog.FileName) == ".api") { adaptivePaletteData = File.ReadAllBytes(openFileDialog.FileName); AdaptivePaletteReader r = new AdaptivePaletteReader(); originalBitmap = r.convertDataToBitmap(adaptivePaletteData); } //open simple image else { originalBitmap = new Bitmap(openFileDialog.FileName); loadMainImage(originalBitmap); Convert_Button.IsEnabled = true; } Save_Button.IsEnabled = true; loadMainImage(originalBitmap); } }