private void SaveImage_Click(object sender, RoutedEventArgs e) { //string strImageID = getImageID(); // Gets the current captured raw bitmap var rawImage = SelectedSnapshot; // If image is selected in the Snapshots ListBox then set it as a save target if (Snapshots.SelectedItem != null) rawImage = (WriteableBitmap)Snapshots.SelectedItem; if (rawImage != null) { // Init the Save File Dialog SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.GetType().GetMethod("set_DefaultFileName").Invoke(saveDialog, new object[] { "FileName.jpg" }); saveDialog.Filter = "Image Files (*.jpg, *.jpeg)|*.jpg;*.jpeg|All Files (*.*)|*.*"; saveDialog.DefaultExt = ".jpg"; saveDialog.FilterIndex = 1; // Show save dialog to the user if ((bool)saveDialog.ShowDialog()) { using (Stream stream = saveDialog.OpenFile()) { // Convert raw captured bitmap to the image that Image Tools understand with the extension method var image = rawImage.ToImage(); // Declare jpeg encoder var encoder = new JpegEncoder(); // Set the image quality encoder.Quality = 90; // Finally encode raw bitmap and save it as a jpg image encoder.Encode(image, stream); // Close the stream stream.Close(); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)