zoukankan      html  css  js  c++  java
  • 在场景里截屏

    /*              #########                       
                  ############                     
                  #############                    
                 ##  ###########                   
                ###  ###### #####                  
                ### #######   ####                 
               ###  ########## ####                
              ####  ########### ####               
             ####   ###########  #####             
            #####   ### ########   #####           
           #####   ###   ########   ######         
          ######   ###  ###########   ######       
         ######   #### ##############  ######      
        #######  #####################  ######     
        #######  ######################  ######    
       #######  ###### #################  ######   
       #######  ###### ###### #########   ######   
       #######    ##  ######   ######     ######   
       #######        ######    #####     #####    
        ######        #####     #####     ####     
         #####        ####      #####     ###      
          #####       ###        ###      #        
            ###       ###        ###              
             ##       ###        ###               
    __________#_______####_______####______________
        身是菩提树,心如明镜台,时时勤拂拭,勿使惹尘埃。
                    我们的未来没有BUG              
    * ==============================================================================
    * Filename: Instering
    * Created:  2017/8/1
    * Author:   WYC
    * Purpose:  截屏
    * ==============================================================================
    */
    using System.Collections;
    using System.IO;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class Instering : MonoBehaviour {
    
    	void Start () {
    		
    	}
    
    
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.A))
            {    
                StartCoroutine(getScreenTexture());
                //截全屏  
                //Application.CaptureScreenshot("shot.png");
            }
        }
    
        public int capx = 0;
        public int capy = 0;
        public int capwidth = 700;
        public int capheight = 500;
        IEnumerator getScreenTexture()
        {
            yield return new WaitForEndOfFrame();
            Texture2D t = new Texture2D(capwidth, capheight, TextureFormat.RGB24, true);//需要正确设置好图片保存格式  
            t.ReadPixels(new Rect(capx, capy, capwidth, capheight), 0, 0, false);//按照设定区域读取像素;注意是以左下角为原点读取  
            t.Apply();
            //二进制转换  
            byte[] byt = t.EncodeToPNG();
            File.WriteAllBytes(Application.dataPath + Time.time + ".png", byt);
        }
    }
    

      

  • 相关阅读:
    团队第二次冲刺第六天
    团队第二次冲刺第五天
    [COCI 2017-2018-1]
    IOI2015day1. boxes
    IOI2015day2. horses
    BZOJ#4898. [Apio2017]商旅
    BZOJ#3267. KC采花
    IOI2016Day2. Messy
    IOI2016Day2. Paint
    BZOJ#1717:[Usaco2006 Dec]Milk Patterns 产奶的模式(后缀数组+单调队列)
  • 原文地址:https://www.cnblogs.com/mclll520/p/7814509.html
Copyright © 2011-2022 走看看