zoukankan      html  css  js  c++  java
  • Unity 保存游戏效果图片,并显示;


     方案1:截屏保存,再显示。
    核心知识:
    1,Application.CaptureScreenshot("wuk.png");Unity会自动截屏保存在 Application.persistentDataPath+"/"+"wuk.png";
    2,WWW 网页;
    3,获取权限;

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />  

    例1:

    public   Material   image;


    void Awake(){  

       Application.CaptureScreenshot("wuk.png");  

    }   

    void Start () {

        StartCoroutine(getCapture());

    }

    IEnumerator   getCapture(){

        path=Application.persistentDataPath;

        Debug.Log("path  "+path);

      www=new WWW("file://"+path+"/wuk.png");  

      yield  return www;  

      image.mainTexture=www.texture;

    }

        方案2:保存指定屏幕区域为png,并显示;

    核心知识:

        Texture2D.ReadPixels;System.IO.File.WriteAllBytes;

    关键方法:

        Texture2D.ReadPixels; Texture2D.Apply();Texture2D.EncodeToPHG;  

    例1:

    string path=Application.persistentDataPath+"/wukuaTurret.jpg";

    public   Material   image;

    IEnumerator getTexture2d()  {  

        yield return new WaitForEndOfFrame();  

        Texture2D t = new Texture2D(200180);

       

        t.ReadPixels(new Rect(200320200180), 00false);  

        t.Apply();  

       

        byte[] byt = t.EncodeToPNG();  

     

      System.IO.File.WriteAllBytes(path, byt);  

    }  

    IEnumerator   getCaptureFf(){

    path=Application.persistentDataPath;

    Debug.Log("path  "+path);

      www=new WWW("file://"+path+"/Screenshot.png");  

      yield  return www;  

      image.mainTexture=www.texture;

    }

  • 相关阅读:
    由当前acitivty直接退到桌面
    Android中SharedPreference多进程数据共享出错
    java回调机制
    Android 监听apk安装替换卸载广播
    jquery中如何退出each循环
    旋转六面体源码
    用CSS3制作的旋转六面体动画
    CSS中常用的字体单位:px、em、rem和%的区别
    css属性简写集合
    小游戏--别踩白块
  • 原文地址:https://www.cnblogs.com/kuangwu/p/2954280.html
Copyright © 2011-2022 走看看