用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - 其他代码库

Unity保存游戏效果图片,并显示出来

2013-10-26 作者: _祥哥哥举报

[其他]代码库

方案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(200, 180);

   

    t.ReadPixels(new Rect(200, 320, 200, 180), 0, 0, false);  

    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;

}



网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...