Unity3d中的几种截图方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity3d中的几种截图方法相关的知识,希望对你有一定的参考价值。
很抱歉所知甚少,目前我仅知道两种截图方式“第一种,用自带的API来做,灵活性一般:Application.CaptureScreenshot ("Screenshot.png");
第二种,读屏幕的图像并保存,需要在协程里面等待一帧,示例如下:
IEnumerator OnScreenCapture ()
yield return new WaitForEndOfFrame();//等待这一帧画完了才能截图
try
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D ( width, height, TextureFormat.RGB24, false);//新建一张图
tex.ReadPixels (new Rect (0, 0, width, height), 0, 0, true);//从屏幕开始读点
byte[] imagebytes = tex.EncodeToJPG ();//用的是JPG(这种比较小)
tex.Compress (false);
tex.Apply();
Texture2D mScreenShotImgae = tex;
File.WriteAllBytes ( @"E:\\Screenshot.png", imagebytes);
catch (System.Exception e)
Debug.Log ("ScreenCaptrueError:" + e);
如果有路过的大神知道其他的截图方法,请一定要告知我,万分感谢。 参考技术A private IEnumerator GetScreenShot(string mfileName)
yield return new WaitForEndOfFrame();
var texture = ScreenCapture.CaptureScreenshotAsTexture();
byte[] tx = texture.EncodeToPNG();
try
File.WriteAllBytes(mfileName, tx);
catch (Exception ex)
Debug.LogError(ex.Message);
java遍历List中的map的几种方法
Student 类
public class Student { private String name; private int age; private int taller; public Student( String name, int age, int taller ) { this.name = name; this.age = age; this.taller = taller; } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("Student [name=").append(name).append(", age=").append(age).append(", taller=").append(taller) .append("]"); return builder.toString(); } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public void setTaller( int taller ) { this.taller = taller; } public int getTaller() { return taller; } }
测试类
import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import PubClass.Student; public class ListAddMap { public static void main( String args[] ) { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map = new HashMap<String, Object>(); Student stu1 = new Student( "\\u5f20\\u4e09", 26, 180 ); Student stu2 = new Student( "\\u674e\\u56db", 28, 175 ); map.put( "stu1", stu1 ); map.put( "stu2", stu2 ); list.add( map ); System.out.println( "方法一 :" ); for( int i = 0; i < list.size(); i++ ) { System.out.println( list.get(i) ); } System.out.println( "方法二 :" ); for( Map<String, Object> mapList : list ) { for( String key : mapList.keySet() ) { System.out.println( key + "-->" + mapList.get(key) ); } } System.out.println( "方法三 :" ); for( int i = 0; i < list.size(); i++ ) { Map<String, Object> mapList = list.get(i); Iterator<String> it = mapList.keySet().iterator(); while( it.hasNext() ) { String str = (String) it.next(); System.out.println( "key-->" + str + "\\t value-->" + map.get(str) ); } } } }
运行结果
以上是关于Unity3d中的几种截图方法的主要内容,如果未能解决你的问题,请参考以下文章