1. 首页
  2. 其他

如何在没有预览的情况下使用 Unity 直接打印照片或文本

本文介绍了如何在没有预览的情况下使用 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# unity 的问题,标记重复的问题不适用于 C# Unity.我通过 LSPrinter Simple 从 Unity 的资产商店解决了.

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.

推荐答案

我使用 Ls 打印机

如果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 AssetsResources"+files);

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

如何在没有预览的情况下使用 Unity 直接打印照片或文本 为WP2原创文章,链接:https://www.wp2.cn/other/%e5%a6%82%e4%bd%95%e5%9c%a8%e6%b2%a1%e6%9c%89%e9%a2%84%e8%a7%88%e7%9a%84%e6%83%85%e5%86%b5%e4%b8%8b%e4%bd%bf%e7%94%a8-unity-%e7%9b%b4%e6%8e%a5%e6%89%93%e5%8d%b0%e7%85%a7%e7%89%87%e6%88%96%e6%96%87/