如何在没有预览的情况下使用Unity直接打印照片或文字 [英] How to direct printing of photo or text using Unity without preview

查看:182
本文介绍了如何在没有预览的情况下使用Unity直接打印照片或文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是unity的初学者,我想在不预览的情况下直接将图像打印到连接的默认打印机上.

I am the beginner on unity, I want to print an image directly to connected default printer without preview.

我正在使用此代码进行打印,但是需要预览

I am using this code for print but it takes the preview

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;



public class PrintImage : MonoBehaviour
{

public void PrintFile()
{
    PrintFiles();
}

void PrintFiles(string path=null)
{

    path = "file:///C:/Users/ersai/Desktop/2.jpg";
    System.Diagnostics.Process process = new System.Diagnostics.Process(); 
    process.StartInfo.CreateNoWindow = false; 
    process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    process.StartInfo.UseShellExecute = true;
    process.StartInfo.FileName = path; 
    process.StartInfo.Verb = "print";

    process.Start(); 

  }
 }

这不是重复的,因为这不是一个窗口标签问题,我问的是C#统一性,标记重复的问题不适用于C#Unity.团结一致的商店为我解决了LSPrinter Simple.

That's was not duplicate because this was not a window tag question I am asking about C# unity the question which tagged duplicate was not working with C# Unity. I am solved by LSPrinter Simple from assest store of unity.

推荐答案

我通过使用如果printerName为空或为null,它将打印到默认打印机.

If printerName is empty or null, it will print to your default printer.

当前,它可以在Windows上运行.每台打印机都应该工作.

Currently, it works on Windows. Every printer should work.

using UnityEngine;
using System.Collections;
using System.Diagnostics;
using System;
using System.IO;
using LCPrinter;
using UnityEngine.UI;

public class LCExampleScript : MonoBehaviour {

public Texture2D texture2D;
public string printerName = "";
public int copies = 1;

public InputField inputField;

public void printSmileButton()
{

    //print the texture2d using on
    // Print.PrintTexture(texture2D.EncodeToPNG(), copies, printerName);*
    Print.PrintTexture(texture2D.EncodeToPNG(), copies, printerName);
}

public void printByPathButton()
{
   //direct path which fill in inputfield
    Print.PrintTextureByPath(inputField.text.Trim(), copies, printerName);
}
}

需要一个小的预览

System.Diagnostics.Process.Start("mspaint.exe", "/pt Assets\\Resources\\"+files);

这篇关于如何在没有预览的情况下使用Unity直接打印照片或文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆