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;
        }
    }
  • 相关阅读:
    IOS中彻底删除mysql方法
    (iOS)Storyboard/xib小技巧
    (iOS)关于GCD死锁的问题
    android-通知Notification
    android-多线程
    android-服务Service
    android-OptionMenu
    android-SQLite 和 Content
    android-数据持久化
    Russia
  • 原文地址:https://www.cnblogs.com/bluebean/p/5746887.html
Copyright © 2011-2022 走看看