1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【PowerShell】クリップボードの画像をPNGファイル化

Last updated at Posted at 2020-04-29

##処理概要
クリップボードの画像を「yyyyMMdd_HHmmss.png」の名前のPNGファイルとして保存。

###処理

clipToPng.ps1
# タイムスタンプ
$time = Get-Date -Format "yyyyMMdd_HHmmss"  
# ファイル名
$filename = $time + ".png" 

# System.Windows.Formsアセンブリを追加
Add-Type -AssemblyName System.Windows.Forms
# クリップボードから画像を取得
$clipboardImage = [Windows.Forms.Clipboard]::GetImage()
# クリップボードに画像が存在する場合
if ([Windows.Forms.Clipboard]::ContainsImage())
{
  # 保存先にデスクトップを指定
  $outputFilePath = Join-Path (Join-Path $Env:UserProfile "Desktop") $filename
  # 保存
  $clipboardImage.Save($outputFilePath)
}

###実行ファイル

run_clipToPng.bat
@echo off
echo clipToPng.ps1を実行中です…
powershell -NoProfile -ExecutionPolicy Unrestricted .\clipToPng.ps1
echo 完了しました!
exit
1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?