Last active
March 21, 2022 09:09
-
-
Save sebinside/ab3908bb00fbeb24fd2c795a07b1f169 to your computer and use it in GitHub Desktop.
Simple c# utility to save images from clipboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Drawing.Imaging; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
namespace ImageQuickSave | |
{ | |
class Program | |
{ | |
private const String saveFileDialogFilter = "Portable Network Graphics (*.png)|*.png|JPEG-Image (*.jpg)|*.jpg|TIFF Image (*.tiff)|*.tiff"; | |
private static readonly ImageFormat[] imageFormats = { ImageFormat.Png, ImageFormat.Jpeg, ImageFormat.Tiff }; | |
[STAThreadAttribute] | |
static void Main(string[] args) | |
{ | |
if (Clipboard.ContainsImage()) | |
{ | |
var image = Clipboard.GetImage(); | |
var saveFileDialog = new SaveFileDialog(); | |
saveFileDialog.Filter = saveFileDialogFilter; | |
saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); | |
if (saveFileDialog.ShowDialog() == DialogResult.OK) { | |
ImageFormat format = imageFormats[saveFileDialog.FilterIndex - 1]; | |
image.Save(saveFileDialog.FileName, format); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment