LoginSignup
12
13

More than 1 year has passed since last update.

Unityで画像をプリンター印刷するだけ。

Last updated at Posted at 2016-01-08

#Unityから保存した画像をそのまま印刷したかったので。
アス比等は引き伸ばされます。印刷するやり方だけ。

1.Pluginsフォルダに『System.drawing.dll』を配置
:::note info
※突っ込みが入ってたので追加。
 unityインストールフォルダ内のSystem.drawing.dllを使ってください
:::
2.以下のスクリプト動かすだけ

print.cs
using UnityEngine;
using System.Collections;
using System.Drawing;

public class Print : MonoBehaviour {

	// Use this for initialization
	void Start () {
        //PrintDocumentオブジェクトの作成
        System.Drawing.Printing.PrintDocument pd =
            new System.Drawing.Printing.PrintDocument();

        //PrintPageイベントハンドラの追加
        pd.PrintPage +=
            new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage);
        //印刷を開始する
        pd.Print();
    }

    private void pd_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)
    {
        //画像を読み込む
        Image img = Image.FromFile("ファイルパス");
        //画像を描画する
        e.Graphics.DrawImage(img, e.MarginBounds);
        //次のページがないことを通知する
        e.HasMorePages = false;
        //後始末をする
        img.Dispose();
    }
}

コードはこちらから引用

http://dobon.net/vb/dotnet/graphics/printdocument.html

プリンターは通常使うプリンターに設定されているもの
また印刷用紙サイズに引き伸ばされます。

12
13
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
12
13