zoukankan      html  css  js  c++  java
  • unity3d 截屏

    原地址:http://www.cnblogs.com/88999660/archive/2013/01/21/2869747.html

    void OnGUI(){
            
            if(GUI.Button(new Rect(10,70,50,50),"ScreenShot")){
                        StartCoroutine(ScreenShot());  //协程调用
            }        
        }
        
        IEnumerator ScreenShot(){
                int width = Screen.width;
                int height = Screen.height;
                yield return new WaitForEndOfFrame(); //去掉协程试试看会发生什么。
                Texture2D tex = new Texture2D(width,height,TextureFormat.RGB24,false);//设置Texture2D
                tex.ReadPixels(new Rect(0,0,width,height),0,0);//获取Pixels           
                tex.Apply();//应用改变
                byte[] bytes = tex.EncodeToPNG();//转换为byte[]
           Destroy(tex);
                Stream flstr = new FileStream(@"d:1.png", FileMode.Create);//文件操作
                BinaryWriter sw = new BinaryWriter(flstr, Encoding.Unicode);           
                sw.Write(bytes);
                sw.Close();
                flstr.Close();    
            
        }
    

      另一种方法:

    using UnityEngine; 
    
    using System.Collections;
     
    public class example : MonoBehaviour 
    
    { 
    
      void OnMouseDown() 
    
      { 
    
        Application.CaptureScreenshot("Screenshot.png"); 
    
      } 
    
    }
     
     
     
    
    function OnGUI(){
        if(GUI.Button(Rect(Screen.width*0.5-50,Screen.height*0.5-50,100,100),"screen")){
            Application.CaptureScreenshot("Screenshot.png");
        }
     }

    这张Screenshot.png图片被存在了当前工程的子目录下了。

  • 相关阅读:
    博客园特效页脚保存
    go channel
    goland 注册
    mac安装go环境
    go 结构体与方法
    gin教程
    hihocoder234周 计算不包含黑点的矩形个数
    参考文献的正确姿势
    vscode用法
    使用extract-text-webpack-plugin提取css文件
  • 原文地址:https://www.cnblogs.com/123ing/p/3703847.html
Copyright © 2011-2022 走看看