mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
fixed #4461: Automatically select correct extension in save as dialog
This commit is contained in:
parent
43e4ebe2e7
commit
af92b14af3
1 changed files with 34 additions and 3 deletions
|
@ -1624,6 +1624,9 @@ public static string SaveImageFileDialog(Image img, string filePath = "", bool u
|
|||
{
|
||||
using (SaveFileDialog sfd = new SaveFileDialog())
|
||||
{
|
||||
sfd.Filter = "PNG (*.png)|*.png|JPEG (*.jpg, *.jpeg, *.jpe, *.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif|GIF (*.gif)|*.gif|BMP (*.bmp)|*.bmp|TIFF (*.tif, *.tiff)|*.tif;*.tiff";
|
||||
sfd.DefaultExt = "png";
|
||||
|
||||
string initialDirectory = null;
|
||||
|
||||
if (useLastDirectory && !string.IsNullOrEmpty(HelpersOptions.LastSaveDirectory) && Directory.Exists(HelpersOptions.LastSaveDirectory))
|
||||
|
@ -1640,12 +1643,40 @@ public static string SaveImageFileDialog(Image img, string filePath = "", bool u
|
|||
initialDirectory = folder;
|
||||
}
|
||||
|
||||
sfd.FileName = Path.GetFileNameWithoutExtension(filePath);
|
||||
sfd.FileName = Path.GetFileName(filePath);
|
||||
|
||||
string ext = Helpers.GetFilenameExtension(filePath);
|
||||
|
||||
if (!string.IsNullOrEmpty(ext))
|
||||
{
|
||||
ext = ext.ToLowerInvariant();
|
||||
|
||||
switch (ext)
|
||||
{
|
||||
case "png":
|
||||
sfd.FilterIndex = 1;
|
||||
break;
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
case "jpe":
|
||||
case "jfif":
|
||||
sfd.FilterIndex = 2;
|
||||
break;
|
||||
case "gif":
|
||||
sfd.FilterIndex = 3;
|
||||
break;
|
||||
case "bmp":
|
||||
sfd.FilterIndex = 4;
|
||||
break;
|
||||
case "tif":
|
||||
case "tiff":
|
||||
sfd.FilterIndex = 5;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sfd.InitialDirectory = initialDirectory;
|
||||
sfd.DefaultExt = "png";
|
||||
sfd.Filter = "PNG (*.png)|*.png|JPEG (*.jpg, *.jpeg, *.jpe, *.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif|GIF (*.gif)|*.gif|BMP (*.bmp)|*.bmp|TIFF (*.tif, *.tiff)|*.tif;*.tiff";
|
||||
|
||||
if (sfd.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(sfd.FileName))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue