LoginSignup
0
0

More than 3 years have passed since last update.

デュアルスクリーンのスクリーンショットをドラッグアンドドロップで切り抜く

Posted at

課題

デュアルスクリーンにしたところ、Windowsデフォルトのスクリーンショットで両方の画面が1枚の画像に写り込んでしまう。
片方の画面だけの画像がほしい。

環境

  • Windows 10
  • 画面は HD縦置き と HD横置き が左右に並んでいる

解決策

  • python + OpenCV で実装
    • OpenCVは日本語パス非対応なのでnumpyを経由する
  • batに画像ファイルをドラッグアンドドロップで実行できるようにする
    • (毎度コマンドを打つのは不便なので)

実装

screenshot-cropper.py
# -*- coding:utf8 -*-
import sys
import os
import cv2
import numpy as np

def main():
    if not (len(sys.argv) == 2):
        return
    img_path = sys.argv[1]
    if not os.path.exists(img_path):
        return
    img_array = np.fromfile(img_path, dtype=np.uint8)
    img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
    img_cropped = img[0:1080, 1080:3000]
    root, ext = os.path.splitext(img_path)
    img_cropped_path = root + '_cropped' + ext
    result, img_cropped_array = cv2.imencode(ext, img_cropped)
    img_cropped_array.tofile(img_cropped_path)

if __name__ == '__main__':
    main()
screenshot-cropper.bat
python "C:\path\to\screenshot-cropper.py" %1

path\to\ は実際のパスにする

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