private void btnGrabImageFromXbox_Click(object sender, RoutedEventArgs e) { // Show Mask ImageGrabMask.Visibility = Visibility.Visible; btnAddImage.IsEnabled = btnGrabImageFromXbox.IsEnabled = false; var backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += (o, args) => { try { // Grab Screenshot from Xbox string screenshotFileName = Path.GetTempFileName(); string screenshotPng = Path.GetTempFileName(); if (!App.AssemblyStorage.AssemblySettings.Xbdm.GetScreenshot(screenshotFileName)) { Dispatcher.Invoke( new Action( () => MetroMessageBox.Show("Not Connected", "You are not connected to a debug Xbox 360, unable to get screenshot"))); return; } // do stuff BitmapSource bitmapSource = DDSConversion.Deswizzle(screenshotFileName, 1204, 720, true, true); // convert to png SaveImage(screenshotPng, bitmapSource); // upload string response = Imgur.UploadToImgur(File.ReadAllBytes(screenshotPng)); string finalString = string.Format("http://i.imgur.com/{0}.png", response); Dispatcher.Invoke(new Action(() => _generatorViewModel.Images.Add(new ModPostInfo.Image { Url = finalString }))); } catch (Exception ex) { Dispatcher.Invoke(new Action(() => MetroException.Show(ex))); } }; backgroundWorker.RunWorkerCompleted += (o, args) => { ImageGrabMask.Visibility = Visibility.Collapsed; btnAddImage.IsEnabled = btnGrabImageFromXbox.IsEnabled = true; }; backgroundWorker.RunWorkerAsync(); }
public HaloScreenshot(string tempImageLocation, LayoutDocument tabItem) { InitializeComponent(); // Convert DDS to BitmapImage _bitmapImage = DDSConversion.Deswizzle(tempImageLocation); // DateTime Creation DateTime date = DateTime.Now; _datetime_long = date.ToString("yyyy-MM-dd,hh-mm-ss"); _datetime_shrt = date.ToString("hh:mm.ss"); // Set Tab Header tabItem.Title = "Screenshot {" + _datetime_shrt + "}"; // Set Image Name lblImageName.Text = _datetime_long + ".png"; // Set Image imageScreenshot.Source = _bitmapImage; // Should I save the image? if (!App.AssemblyStorage.AssemblySettings.XdkAutoSave) { return; } if (!Directory.Exists(App.AssemblyStorage.AssemblySettings.XdkScreenshotPath)) { Directory.CreateDirectory(App.AssemblyStorage.AssemblySettings.XdkScreenshotPath); } string filePath = App.AssemblyStorage.AssemblySettings.XdkScreenshotPath + "\\" + _datetime_long + ".png"; SaveImage(filePath); }