Skip to content

Instantly share code, notes, and snippets.

@sebinside
Last active March 21, 2022 09:09
Show Gist options
  • Save sebinside/ab3908bb00fbeb24fd2c795a07b1f169 to your computer and use it in GitHub Desktop.
Save sebinside/ab3908bb00fbeb24fd2c795a07b1f169 to your computer and use it in GitHub Desktop.
Simple c# utility to save images from clipboard.
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