using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
using System;
using System.IO;
//截取当前摄像机捕抓的画面
public void CaptureScreen(Camera c, Rect r)
{
RenderTexture rt = new RenderTexture((int)r.width, (int)r.height, 0);
c.targetTexture = rt;
c.Render();
RenderTexture.active = rt;
Texture2D screenShot = new Texture2D((int)r.width, (int)r.height, TextureFormat.RGB24, false);
screenShot.ReadPixels(r, 0, 0);
screenShot.Apply();
c.targetTexture = null;
RenderTexture.active = null;
Destroy(rt);
string fileName = DateTime.Now.Ticks + ".jpg";
//把图像转换为JPG格式 并设置质量
byte[] bytes = screenShot.EncodeToJPG(50);
string url = "http://xxxxxxxxxxxxx";
WWWForm form = new WWWForm();
form.AddField("filename", fileName);
form.AddBinaryData("photo", bytes,"111.jpg", "image/jpg");
WWW www = new WWW(url, form);
StartCoroutine(PostData(www));
}
unity3d截取屏幕并上传到服务器 工具类
最新推荐文章于 2024-07-24 15:25:23 发布