zoukankan      html  css  js  c++  java
  • unity3d使用脚本保存屏幕截图

    using UnityEngine;
    using System.Collections;
    using System.IO;
    
    public class FrameAnimation : MonoBehaviour {
        public Texture2D image;
        public int w;
        public int h;
        public float nextTime = 0.0f;
        public float rate = 0.3f;
        int i = 0;
        // Use this for initialization
        void Start () {
            w = Screen.width;
            h = Screen.height;
            image = new Texture2D(w, h);
        }
        
        // Update is called once per frame
        void Update () {
            if (Input.GetMouseButton(0) && Time.time > nextTime)
            {
                nextTime = Time.time + rate;
                i++;
                StartCoroutine(SaveImage(i));
            }
        }
    
        IEnumerator SaveImage(int i)
        {
            yield return new WaitForEndOfFrame();
            image.ReadPixels(new Rect(0, 0, w, h), 0, 0, true);//read pixels from screen to texture
            image.Apply();
            byte[] bytes = image.EncodeToPNG();
            File.WriteAllBytes(Application.streamingAssetsPath + "/" + i + ".png", bytes);
            Debug.Log("write a pic");
            yield return null;
        }
    }
  • 相关阅读:
    统计一行字符串中每个字母个数
    不定宽高的文字在div中垂直居中
    转:Python 与 Excel 不得不说的事
    Centos 6安装python3.5
    day04
    day03
    Day02
    python ciscolib模块
    三级菜单
    模拟登陆系统
  • 原文地址:https://www.cnblogs.com/bluebean/p/5746887.html
Copyright © 2011-2022 走看看