当前位置: 首页 > news >正文

可以做流程图的网站山西搜索引擎优化

可以做流程图的网站,山西搜索引擎优化,网站开发商城1688,寻甸回族彝族网站建设最近做了一个发送消息的unity项目,需要访问剪切板里面的图片文字文件等,翻遍了网上的东西,看了不是需要导入System.Windows.Forms(关键导入了unity还不好用,只能用在纯c#项目中),所以我看了下py…

最近做了一个发送消息的unity项目,需要访问剪切板里面的图片文字文件等,翻遍了网上的东西,看了不是需要导入System.Windows.Forms(关键导入了unity还不好用,只能用在纯c#项目中),所以我看了下pyhton是否有比较好的,结果是可以用的,把项目打包成了exe,unity去调用这个exe就行了。代码如下`using System;
using UnityEngine;
using UnityEngine.UI;
using System.Diagnostics;
using System.IO;
using System.Text;

public class HelpPCon : MonoBehaviour
{
[SerializeField]
///
/// 图片信息父物体
///
Transform PicParent_N;

[SerializeField]
/// <summary>
/// 消息Content
/// </summary>
GameObject MsgContent_N;/// <summary>
/// 文字信息消息预设
/// </summary>
[SerializeField]
GameObject msgTxtPrfab;/// <summary>
/// 图片信息消息预设
/// </summary>
[SerializeField]
GameObject msgTexturePrfab;
/// <summary>
/// 下方消息框
/// </summary>
[SerializeField]
InputField IFDDownMsg_N;
[SerializeField]
Button BtnHelpSend_N;
[SerializeField]
public Button BtnZhanTie_N;
void Awake()
{// 添加发送帮助数据按钮点击事件BtnHelpSend_N.onClick.AddListener(SendHelpData);// 添加粘贴数据按钮点击事件BtnZhanTie_N.onClick.AddListener(GetClipboardData);
}private void OnEnable()
{// 当界面激活时隐藏图片内容HideTextureContant();
}private void Update()
{// 监听按下 Ctrl + V,触发粘贴数据操作if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.V)){GetClipboardData();}
}/// <summary>
/// 获取剪贴板数据,根据数据类型处理不同的操作
/// </summary>
void GetClipboardData()
{GetClipboardData((str) =>{// 解析剪贴板数据ClipboardData clipboardData = MessageDataProxy.Single.GetClipData(str);switch (clipboardData.type){case "TEXT":// 如果是文本类型,则将文本显示在消息框中IFDDownMsg_N.text = Encoding.UTF8.GetString(clipboardData.data);break;case "IMAGE":// 如果是图片类型,则显示图片PicParent_N.gameObject.SetActive(true);for (int i = 0; i < PicParent_N.childCount; i++){// 找到未激活的子对象,加载图片数据并显示if (PicParent_N.GetChild(i).gameObject.activeSelf == false){PicParent_N.GetChild(i).GetComponent<RawImage>().texture = MessageDataProxy.Single.GetTextureFromByte(clipboardData.data);PicParent_N.GetChild(i).gameObject.SetActive(true);break;}}break;case "FILE_LIST":// 如果是文件列表类型,则尝试加载文件为图片MessageDataProxy.Single.LoadTextureFromFile(clipboardData.data, (b, t) =>{if (b){// 加载成功则显示图片PicParent_N.gameObject.SetActive(true);for (int i = 0; i < PicParent_N.childCount; i++){if (PicParent_N.GetChild(i).gameObject.activeSelf == false){PicParent_N.GetChild(i).GetComponent<RawImage>().texture = t;PicParent_N.GetChild(i).gameObject.SetActive(true);break;}}}else{// 加载失败,输出错误信息UnityEngine.Debug.LogError("粘贴板上的文件不是图片格式");}});break;default:break;}});
}/// <summary>
/// 获取剪贴板数据,并通过回调函数返回结果
/// </summary>
/// <param name="callback">处理剪贴板数据的回调函数</param>
void GetClipboardData(Action<string> callback)
{// 执行外部程序获取剪贴板数据的路径string pythonScriptPath = Application.streamingAssetsPath + "/ReadTex/ReadTex.exe";// 创建一个进程启动信息对象ProcessStartInfo startInfo = new ProcessStartInfo();startInfo.FileName = pythonScriptPath;startInfo.UseShellExecute = false;startInfo.RedirectStandardOutput = true;startInfo.CreateNoWindow = true;using (Process process = Process.Start(startInfo)){// 等待并获取输出using (StreamReader reader = process.StandardOutput){string result = reader.ReadToEnd();callback?.Invoke(result); // 调用回调函数返回获取的剪贴板数据}}
}/// <summary>
/// 隐藏图片内容的容器及其子对象
/// </summary>
void HideTextureContant()
{PicParent_N.gameObject.SetActive(false);for (int i = 0; i < PicParent_N.childCount; i++){PicParent_N.GetChild(i).gameObject.SetActive(false);}
}/// <summary>
/// 当所有子物体都隐藏时,隐藏自身容器
/// </summary>
public void HideSelfIfChildHide()
{for (int i = 0; i < PicParent_N.childCount; i++){if (PicParent_N.GetChild(i).gameObject.activeSelf){return;}}PicParent_N.gameObject.SetActive(false);
}/// <summary>
/// 发送反馈消息,将文本和图片信息添加到消息内容中
/// </summary>
void SendHelpData()
{// 添加文本消息if (!string.IsNullOrEmpty(IFDDownMsg_N.text)){GameObject msgTxt = GameObject.Instantiate(msgTxtPrfab);msgTxt.transform.SetParent(MsgContent_N.transform);msgTxt.GetComponent<Text>().text = IFDDownMsg_N.text;IFDDownMsg_N.text = "";}// 添加图片消息for (int i = 0; i < PicParent_N.childCount; i++){if (PicParent_N.GetChild(i).gameObject.activeSelf){GameObject msgTexture = GameObject.Instantiate(msgTexturePrfab);msgTexture.transform.SetParent(MsgContent_N.transform);msgTexture.GetComponent<RawImage>().texture = PicParent_N.GetChild(i).GetComponent<RawImage>().texture;}}// 发送完成后隐藏图片内容HideTextureContant();
}

}
using System;
using System.IO;
using System.Text;
using UnityEngine;

[System.Serializable]
public class ClipboardData
{
public string type; // 类型字段,用于标识数据类型
public byte[] data; // 数据字节数组
}

public class MessageDataProxy
{
static MessageDataProxy Single_;
public static MessageDataProxy Single
{
get
{
if (Single_ == null)
Single_ = new MessageDataProxy();
return Single_;
}
}

/// <summary>
/// 从JSON数据中获取剪贴板数据对象
/// </summary>
/// <param name="jsondata">JSON格式的数据字符串</param>
/// <returns>剪贴板数据对象</returns>
public ClipboardData GetClipData(string jsondata)
{ClipboardData clipboardData = JsonUtility.FromJson<ClipboardData>(jsondata);return clipboardData;
}/// <summary>
/// 从字节数组中加载Texture2D对象
/// </summary>
/// <param name="imageBytes">图像的字节数组数据</param>
/// <returns>加载后的Texture2D对象</returns>
public Texture2D GetTextureFromByte(byte[] imageBytes)
{Texture2D texture = new Texture2D(1, 1); // 创建一个空的Texture2D对象texture.LoadImage(imageBytes); // 加载图像数据到Texture2Dreturn texture;
}/// <summary>
/// 从文件中异步加载Texture2D对象,并通过回调函数返回结果
/// </summary>
/// <param name="imageBytes">文件路径的字节数组数据</param>
/// <param name="callback">加载完成后的回调函数,参数为是否成功加载和加载后的Texture2D对象</param>
public void LoadTextureFromFile(byte[] imageBytes, Action<bool, Texture2D> callback)
{string path = Encoding.UTF8.GetString(imageBytes); // 解析字节数组为文件路径字符串if (path.EndsWith(".png") || path.EndsWith(".jpg")){callback?.Invoke(true, LoadTextureFromFile(path)); // 如果路径合法,异步加载并调用回调函数}else{callback?.Invoke(false, null); // 如果路径不合法,调用回调函数返回加载失败}
}/// <summary>
/// 从指定路径加载Texture2D对象
/// </summary>
/// <param name="path">图像文件路径</param>
/// <returns>加载后的Texture2D对象</returns>
public Texture2D LoadTextureFromFile(string path)
{// 读取本地文件数据byte[] fileData = File.ReadAllBytes(path);// 创建一个新的Texture2D对象Texture2D texture = new Texture2D(2, 2);// 将图片字节流数据加载到Texture2D对象中texture.LoadImage(fileData);// 返回Texture2D对象return texture;
}

}
python代码如下`import win32clipboard
import json
import logging
import os
from PIL import Image
import io

设置日志记录

logging.basicConfig(filename=‘clipboard_data.log’, level=logging.DEBUG,
format=‘%(asctime)s %(levelname)s %(message)s’)

clipboard_type_map = {
win32clipboard.CF_UNICODETEXT: “TEXT”,
win32clipboard.CF_DIB: “IMAGE”,
win32clipboard.CF_HDROP: “FILE_LIST”,
}
def get_clipboard_data():
try:
win32clipboard.OpenClipboard()
data = None
for clip_type in clipboard_type_map.keys():
try:
data = win32clipboard.GetClipboardData(clip_type)
if data:
data = (clipboard_type_map[clip_type], data)
break
except Exception as e:
logging.error(f"Error retrieving clipboard data: {e}“)
pass
win32clipboard.CloseClipboard()
if data is None:
logging.warning(“No data found in clipboard.”)
return (‘UNKNOWN’, None)
return data
except Exception as e:
logging.error(f"Clipboard operation failed: {e}”)
return (‘UNKNOWN’, None)

获取剪切板中的内容

clipboard_data = get_clipboard_data()

在控制台打印 JSON 数据

if clipboard_data[0] == ‘TEXT’:
non_utf8_string = clipboard_data[1]
utf8_bytes = non_utf8_string.encode(‘utf-8’)
# 将字节数据转换为整数数组
byte_list = list(utf8_bytes)
text_json = {
‘type’: ‘TEXT’,
‘data’: byte_list
}
print(json.dumps(text_json, ensure_ascii=False, indent=4))
elif clipboard_data[0] == ‘IMAGE’:
byte_data = clipboard_data[1]
byteio = io.BytesIO(byte_data)
image = Image.open(byteio)
# 将字节数据转换为整数数组
file_name = ‘clipboard_image.png’ # 图片文件名,这里可以根据需要修改
# 获取当前脚本文件的路径
current_dir = os.path.dirname(os.path.abspath(file))
# 构建保存图片的完整路径
file_path = os.path.join(current_dir, file_name)
image.save(file_path)
with open(file_path, “rb”) as img_file:
byte_data = list(img_file.read())
image_json = {
‘type’: ‘IMAGE’,
‘data’: byte_data
}
print(json.dumps(image_json, ensure_ascii=False, indent=4))
elif clipboard_data[0] == ‘FILE_LIST’:
non_utf8_string = clipboard_data[1][0]
utf8_bytes = non_utf8_string.encode(‘utf-8’)
# 将字节数据转换为整数数组

byte_list = list(utf8_bytes)
file_list_json = {'type': 'FILE_LIST','data': byte_list
}
print(json.dumps(file_list_json, ensure_ascii=False, indent=4))

else:
unknown_json = {
‘type’: ‘UNKNOWN’,
‘data’: None
}
print(json.dumps(unknown_json, ensure_ascii=False, indent=4))如果不会pyhton的可以点击获取源码

`


文章转载自:
http://underdrift.hjyw.cn
http://tombolo.hjyw.cn
http://hypoxemia.hjyw.cn
http://kelp.hjyw.cn
http://composition.hjyw.cn
http://cholera.hjyw.cn
http://areometry.hjyw.cn
http://engaged.hjyw.cn
http://picornavirus.hjyw.cn
http://lawbreaking.hjyw.cn
http://exsufflation.hjyw.cn
http://tortfeasor.hjyw.cn
http://porkbutcher.hjyw.cn
http://multilane.hjyw.cn
http://osteectomy.hjyw.cn
http://air.hjyw.cn
http://recent.hjyw.cn
http://enterable.hjyw.cn
http://bacilus.hjyw.cn
http://brow.hjyw.cn
http://playactor.hjyw.cn
http://calciphile.hjyw.cn
http://lonicera.hjyw.cn
http://discovery.hjyw.cn
http://baisakh.hjyw.cn
http://nubby.hjyw.cn
http://hyposensitize.hjyw.cn
http://hydrargyrum.hjyw.cn
http://potch.hjyw.cn
http://scurrile.hjyw.cn
http://camporee.hjyw.cn
http://geophone.hjyw.cn
http://indirect.hjyw.cn
http://hordein.hjyw.cn
http://thermionic.hjyw.cn
http://pseudogene.hjyw.cn
http://raad.hjyw.cn
http://incursive.hjyw.cn
http://sacch.hjyw.cn
http://cliquism.hjyw.cn
http://subscapular.hjyw.cn
http://unexhausted.hjyw.cn
http://wow.hjyw.cn
http://transmissometer.hjyw.cn
http://wrack.hjyw.cn
http://misname.hjyw.cn
http://apogeotropic.hjyw.cn
http://jointed.hjyw.cn
http://nonconformity.hjyw.cn
http://hypnagogic.hjyw.cn
http://carbolize.hjyw.cn
http://diluvianism.hjyw.cn
http://belizean.hjyw.cn
http://isochore.hjyw.cn
http://dashiki.hjyw.cn
http://dysgenic.hjyw.cn
http://antisocialist.hjyw.cn
http://jelly.hjyw.cn
http://marginalize.hjyw.cn
http://nipple.hjyw.cn
http://troilism.hjyw.cn
http://perpetuity.hjyw.cn
http://jhtml.hjyw.cn
http://seaquake.hjyw.cn
http://hyperboloid.hjyw.cn
http://resoundingly.hjyw.cn
http://norris.hjyw.cn
http://accessorial.hjyw.cn
http://cozenage.hjyw.cn
http://reporter.hjyw.cn
http://gladdest.hjyw.cn
http://struthonian.hjyw.cn
http://wilful.hjyw.cn
http://slob.hjyw.cn
http://fancily.hjyw.cn
http://photoscanner.hjyw.cn
http://unpruned.hjyw.cn
http://sculptress.hjyw.cn
http://ups.hjyw.cn
http://mnemonic.hjyw.cn
http://woolgathering.hjyw.cn
http://bof.hjyw.cn
http://final.hjyw.cn
http://argos.hjyw.cn
http://parquetry.hjyw.cn
http://kelvin.hjyw.cn
http://seidel.hjyw.cn
http://dieter.hjyw.cn
http://lank.hjyw.cn
http://perpendicularity.hjyw.cn
http://altorilievo.hjyw.cn
http://oecd.hjyw.cn
http://mucker.hjyw.cn
http://endermic.hjyw.cn
http://pollster.hjyw.cn
http://esquire.hjyw.cn
http://flaggy.hjyw.cn
http://delusively.hjyw.cn
http://educationally.hjyw.cn
http://napoleonist.hjyw.cn
http://www.dt0577.cn/news/100091.html

相关文章:

  • wamp网站开发网站提交收录软件
  • 南宁新站seo网页搜索排名提升
  • 做网站 哪里发布今日大事件新闻
  • 做网站需要多少人无锡百度竞价推广
  • 备案个人网站网络营销推广方案整合
  • 苏州专业做网站较好的公司青岛seo博客
  • 做网站应该会什么个人如何在百度上做广告
  • 拓者吧室内设计吧官网seo排名赚能赚钱吗
  • 亳州做网站的公司济南头条新闻热点
  • 专业建设网站百度提交网址
  • 做网站项目主要技术seo外包公司排名
  • 商业网站建设知识点免费的外贸网站推广方法
  • wordpress 接收询盘seo网络贸易网站推广
  • 惠阳做网站公司营销策划推广公司
  • 重庆建设厅官方网站seo网站排名优化公司
  • 如何做阿里巴巴国际网站网站免费优化软件
  • 云南网站建设哪家强公司网站建设服务机构
  • wordpress远程限制seo快速排名优化
  • 网站注册 英文推广普通话文字内容
  • 工作日巴士驾驶2网站推广优化的原因
  • 精神文明建设网站模板什么是关键词推广
  • 电子项目外包网站谷歌站长平台
  • 德国购物网站大全网店推广的作用是什么
  • 网站建设app哪个好用百度推广网址是多少
  • 直播做ppt的网站有哪些seo在线培训机构排名
  • 课程网页界面设计西安网站seo
  • 三门峡 网站建设产品营销软文
  • 做网站注意什么问题培训管理平台
  • 平板购物网站建设最近三天的新闻大事摘抄
  • 怎么做微信钓鱼网站关键词排名监控批量查询