I posted a little utlity I wrote a while back called ClipboardToImage.This app does one thing, it takes the contents of your clipboard (an image) ad saves it to disk using a number of fileformat options. I wrote this so that I could use Alt-PrtScn, save to disk and then post to my blog. Prior to that you need to launch a program like Paint.exe (which is scary to use), find a way to crop, and then save.
This reduces the number of steps and makes it really easy. Place ClipboardToImage.exe in a portable/launchable place and just run it when you have your screen shot on the clipboard. It will then ask you where you want to save the image and with which format.
Oh, it does one other bonus. If the contents of the clipboard is text, then it will remove any linebreaks (like in broken urls).
I basically use ClipboardToImage for window screenshots and Cropper for all the others. It's a winning combination
.
Enjoy.
Here is the code for the app:
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
namespace ClipboardToImage
{
/// <summary>
/// Summary description for ImageType.
/// </summary>
public enum ImageType : short
{
Png = 1,
Jpeg = 2,
Gif = 3,
Bmp = 4
}
/// <summary>
/// Summary description for Program.
/// </summary>
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
object image = GetClipboardContents();
ImageType imageType = ImageType.Png;
if (args.Length > 0)
{
try
{
imageType = (ImageType)Enum.Parse(typeof(ImageType), args[0], true);
}
catch
{
// TODO: spit out command line help
}
}
if (image is Bitmap)
{
SaveImage((Bitmap)image, imageType);
}
}
private static void SaveImage(Bitmap bitmap, ImageType type)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "PNG file (*.png)|*.png|Jpeg file
(*.jpg)|*.jpg|GIF file (*.gif)|*.gif|Bitmap file (*.bmp)|*.bmp|All files (*.*)|*.*" ;
switch(type)
{
case(ImageType.Png):
saveFileDialog1.FilterIndex = 1 ;
saveFileDialog1.DefaultExt = "png";
break;
case(ImageType.Jpeg):
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.DefaultExt = "jpg";
break;
case(ImageType.Gif):
saveFileDialog1.FilterIndex = 3 ;
saveFileDialog1.DefaultExt = "gif";
break;
case(ImageType.Bmp):
saveFileDialog1.FilterIndex =4 ;
saveFileDialog1.DefaultExt = "bmp";
break;
default:
break;
}
DialogResult dr = saveFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
string fileName = saveFileDialog1.FileName;
switch(saveFileDialog1.FilterIndex)
{
case(1):
bitmap.Save(fileName, ImageFormat.Png);
break;
case(2):
bitmap.Save(fileName, ImageFormat.Jpeg);
break;
case(3):
bitmap.Save(fileName, ImageFormat.Gif);
break;
case(4):
bitmap.Save(fileName, ImageFormat.Bmp);
break;
default:
break;
}
}
bitmap.Dispose();
}
private static object GetClipboardContents()
{
IDataObject iData = Clipboard.GetDataObject();
System.IO.MemoryStream ms = new MemoryStream();
// Determines whether the data is in a format you can use.
if(iData.GetDataPresent(DataFormats.Bitmap))
{
Bitmap bitmap = (Bitmap)iData.GetData(DataFormats.Bitmap);
bitmap.Save(ms, ImageFormat.Bmp);
return bitmap;
}
else
return null;
}
}
}