ソースコード
クリップボードから画像データを取得して、名前を付けて保存する。
ClipImage.cs
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace ClipImage
{
public static class Program
{
[STAThread]
static void Main(string[] args)
{
try
{
Execute(args);
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Error");
}
}
static void Execute(string[] args)
{
var img = Clipboard.GetImage();
if (img == null)
{
throw new Exception("Empty.");
}
var sfd = new SaveFileDialog();
sfd.FileName = "新しいファイル.jpeg";
sfd.Filter = "画像ファイル(*.jpeg)|*.jpeg";
if (args.Length == 0)
{
sfd.InitialDirectory = @"C:\";
}
else
{
sfd.InitialDirectory = args[0];
}
if (sfd.ShowDialog() == DialogResult.OK)
{
img.Save(sfd.FileName, ImageFormat.Jpeg);
}
}
}
}
コンパイル
csc.exeでコンパイルする。
csc.exe /out:clipimage.exe /target:winexe ClipImage.cs
コンテキストメニューへ追加
以下のレジストリの場所へ
HKEY_CLASSES_ROOT\Directory\Background\shell\IMAGE♪
以下の値を追加
キー名:command
値:"C:\{exeの配置場所}\clipimage.exe" "%V"
※やる前へ念のために、元に戻せるのでレジストリをエクスポートしておくのを推奨