Unity 截屏,WWW加载图片,保存到本地
来源:互联网 发布:女生学java还是web前端 编辑:程序博客网 时间:2024/05/18 19:42
using UnityEngine;using System.Collections;using System.IO;public class NewBehaviourScript : MonoBehaviour { private Texture2D tex;void Start () { CaptureScreenshot2(new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 1f, Screen.height * 1f)); StartCoroutine(GetImage());}// Update is called once per framevoid Update () {} IEnumerator GetImage() { string dir = Application.persistentDataPath; string filePath = dir + "hello" + ".png"; string url = "file://" + Application.dataPath + "/StreamingAssets/" + "1.jpg"; WWW www = new WWW(url); yield return www; tex = www.texture; byte[] pngData = tex.EncodeToPNG(); File.WriteAllBytes(filePath, pngData); } public IEnumerator CaptureScreenshot() { yield return new WaitForEndOfFrame(); Rect rect = new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 1f, Screen.height * 1f); // 先创建一个的空纹理,大小可根据实现需要来设置 Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false); // 读取屏幕像素信息并存储为纹理数据, screenShot.ReadPixels(rect, 0, 0); screenShot.Apply(); // 然后将这些纹理数据,成一个png图片文件 byte[] bytes = screenShot.EncodeToJPG(); string filename = Application.persistentDataPath + "/Screenshot.jpg"; System.IO.File.WriteAllBytes(filename, bytes); }}
0 0
- Unity 截屏,WWW加载图片,保存到本地
- 【Unity】Unity中通过纹理截屏将图片保存到本地
- Unity实现 下载网络资源到本地 WWW加载
- 保存图片到本地
- 图片保存到本地
- 图片保存到本地
- 保存图片到本地
- 图片保存到本地
- Glide加载图片并保存到本地相册
- Glide加载图片并保存到本地返回file,bitmap
- Glide加载图片并保存到本地返回file,bitmap
- 使用AsyncTask加载网络图片并保存到手机本地
- unity中使用www加载本地资源
- Unity 下载图片并保存(WWW)
- Unity 加载本地图片文件
- Unity3d-WWW实现图片资源显示以及保存和本地加载
- AIR保存图片到本地
- 保存远程图片到本地
- 让服务器iis支持.apk文件下载的设置方法
- CRF专业领域实体识别
- spark streaming接kafka数据方式汇总
- Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException
- 第四周项目1:求最大公约数
- Unity 截屏,WWW加载图片,保存到本地
- C# Winform中窗体的美化——用IrisSkin4.dll美化你的WinForm
- 基于tiny4412的Linux内核移植(支持device tree)(二)
- Hadoop模板(新API)
- 菜鸟成长记-UIPickerView使用
- java反射机制demo
- SQL Server中行列转换 Pivot UnPivot
- 通达信股本变迁文件(gbbq)解密方法
- list同对象合并并汇总指定属性