LoginSignup
5

More than 5 years have passed since last update.

コマンドラインから画像ファイルの中身をクリップボードに転送する。

Last updated at Posted at 2012-11-14

コマンドラインからファイル名を指定すれば、画像をクリップボードにコピーします。
gnuplot等、別のプログラムで作った画像ファイルの中身をWord等に貼り付けるとき、これをかます事で「ペイントで開く→全指定→コピー」の手間を減らします。

img2clip.fs
open System.IO
open System.Drawing
open System.Windows.Forms
open System

let copy_image (fname: string) = 
    try
        use fs = new FileStream(fname,FileMode.Open, FileAccess.Read)
        use bmp = new Bitmap( System.Drawing.Image.FromStream(fs) ) ;
        Clipboard.SetData("Bitmap", bmp)
    with
        :? System.ArgumentException -> 
            printfn "can't open %s" fname
            exit 1

let main =
    let args = Environment.GetCommandLineArgs()
    if args.Length <> 2 then
        printfn "usage:img2clip imgfile" |> ignore
        Environment.Exit  1
    let infile = args.[1]
    copy_image infile

[<STAThread>]
do main

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5