private async Task<string> WriteTempThumbnailImageAsync(ImageSource mapImageSource)
{
// Create a new encoder for jpeg images
var jpegEncoder = new JpegBitmapEncoder { QualityLevel = 70 };
// Create a bitmap frame to represent the image
var mapImageBitmapSource = mapImageSource as BitmapSource;
var mapImageFrame = BitmapFrame.Create(mapImageBitmapSource);
// Add the frame to the jpeg encoder frames collection
jpegEncoder.Frames.Add(mapImageFrame);
// Get the folder for the current executable
var folder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
// Build the output file name with the executable directory
var outFile = new FileInfo(Path.Combine(folder, "MapThumbnail_Temp"));
// If the file already exists, delete it
if (outFile.Exists)
{
await Task.Delay(1000);
outFile.Delete();
}
// Create the output image file
using (var stm = File.Create(outFile.FullName))
{
jpegEncoder.Save(stm);
}
// Return the path to the file
return outFile.FullName;
}