webplayer的截图实现
来源:互联网 发布:淘宝网店申请 编辑:程序博客网 时间:2024/05/16 10:44
首先是建一个 C# 类:
using System;
using UnityEngine;
using System.Collections;
public class PostPng
{
public static string UploadUrl = http://127.0.0.1/getpng.php;
public static void UploadPNG(MonoBehaviour thread, string fileName, Action<bool> result)
{
thread.StartCoroutine(UploadPNG(fileName, result));
}
private static IEnumerator UploadPNG(string fileName, Action<bool> result)
{
yield return new WaitForEndOfFrame();
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
byte[] bytes = tex.EncodeToPNG();
GameObject.Destroy(tex);
WWWForm form = new WWWForm();
form.AddField("enctype", "multipart/form-data");
form.AddBinaryData("PngUpload", bytes, fileName, "image/png");
WWW post = new WWW(UploadUrl , form);
yield return post;
if (string.IsNullOrEmpty(post.error) && result != null)
{
result(true);
}
else
{
result(false);
}
post.Dispose();
}
}
再建一个 Cube,再建一个 C# 脚本:
OnGUI()
{
if (GUI.Button(new Rect(440, Screen.height - 25, 65, 23), "Snapshot"))
{
LoadHelp.UploadPNG(this, "Snapshot", delegate(bool result)
{
if (result)
{
Application.ExternalEval("alert('ok')");
}
});
}
}
最后要建立一个接受图片上传的程序,用什么取决于你的web服务器,我这里用的是php:
<?php
$filename = "";
$field = "PngUpload";
$pngfolder = "snapshot/";
if ($_FILES[$field]["error"] > 0)
{
echo "Error: " . $_FILES[$field]["error"];
}
else
{
$filename = $pngfolder . $_FILES[$field]["name"] . ".png";
move_uploaded_file($_FILES[$field]["tmp_name"], $filename);
echo("ok");
}
?>
using System;
using UnityEngine;
using System.Collections;
public class PostPng
{
public static string UploadUrl = http://127.0.0.1/getpng.php;
public static void UploadPNG(MonoBehaviour thread, string fileName, Action<bool> result)
{
thread.StartCoroutine(UploadPNG(fileName, result));
}
private static IEnumerator UploadPNG(string fileName, Action<bool> result)
{
yield return new WaitForEndOfFrame();
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
byte[] bytes = tex.EncodeToPNG();
GameObject.Destroy(tex);
WWWForm form = new WWWForm();
form.AddField("enctype", "multipart/form-data");
form.AddBinaryData("PngUpload", bytes, fileName, "image/png");
WWW post = new WWW(UploadUrl , form);
yield return post;
if (string.IsNullOrEmpty(post.error) && result != null)
{
result(true);
}
else
{
result(false);
}
post.Dispose();
}
}
再建一个 Cube,再建一个 C# 脚本:
OnGUI()
{
if (GUI.Button(new Rect(440, Screen.height - 25, 65, 23), "Snapshot"))
{
LoadHelp.UploadPNG(this, "Snapshot", delegate(bool result)
{
if (result)
{
Application.ExternalEval("alert('ok')");
}
});
}
}
最后要建立一个接受图片上传的程序,用什么取决于你的web服务器,我这里用的是php:
<?php
$filename = "";
$field = "PngUpload";
$pngfolder = "snapshot/";
if ($_FILES[$field]["error"] > 0)
{
echo "Error: " . $_FILES[$field]["error"];
}
else
{
$filename = $pngfolder . $_FILES[$field]["name"] . ".png";
move_uploaded_file($_FILES[$field]["tmp_name"], $filename);
echo("ok");
}
?>
0 0
- webplayer的截图实现
- unity3d webplayer 截图实现
- 截图功能的实现
- 不规则截图的实现
- iOS 截图的实现
- 圆形截图(不规则截图)的实现
- C#屏幕截图的实现
- iOS实现截图的代码
- 截图功能的简单实现
- delphi 截图简单的实现
- java截图工具的实现
- 截图保存功能的实现
- 截图软件的编程实现
- unity3D发布webplayer,在webplayer中打开新的标签页
- MATLAB实现截图功能,返回屏幕截图的RGB数组
- 基于Qt的截图工具,实现截图后进行编辑
- 分享内容的截图的实现方法
- extjs的头像截图功能的实现
- 近20个绚丽实用的jQuery/CSS3侧边栏菜单
- 经典算法——顺时针打印矩阵
- 2016.03.09
- 判断一个单链表是否有环及环的链接点
- 【项目管理和构建】——Maven下载、安装和配置(二)
- webplayer的截图实现
- 自己所掌握的知识及工作经验
- java实现mysql数据库的导出
- mybatis--动态sql
- Android LocalSocket进程通信
- statusCode(状态码) 200、300、400、500序列
- jdk环境变量配置
- 设计模式之职责链模式
- Android Touch事件传递