unity3d 屏幕截图
2015-10-28 10:23
309 查看
function ScreenshotEncode()
{
// wait for graphics to render
yield WaitForEndOfFrame();
// create a texture to pass to encoding
var texture:Texture2D = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
// put buffer into texture
texture.ReadPixels(Rect(0.0, 0.0, Screen.width, Screen.height), 0.0, 0.0);
texture.Apply();
// split the process up--ReadPixels() and the GetPixels() call inside of the encoder are both pretty heavy
yield;
// create our encoder for this texture
var encoder:JPGEncoder = new JPGEncoder(texture, 75.0);
// encoder is threaded; wait for it to finish
while(!encoder.isDone)
yield;
// save our test image (could also upload to WWW)
File.WriteAllBytes(Application.dataPath + "/../testscreen-" + count + ".jpg", encoder.GetBytes());
count++;
}
//简便方法看下面:
function OnMouseDown() {
Application.CaptureScreenshot("Screenshot.png");
}
// The folder we place all screenshots inside.
// If the folder exists we will append numbers to create an empty folder.
var folder = "ScreenshotFolder";
var frameRate = 25; //每秒25帧。
private var realFolder = "";
function Start () {
// Set the playback framerate!
// (real time doesn't influence time anymore)
Time.captureFramerate = frameRate;
// Find a folder that doesn't exist yet by appending numbers!
realFolder = folder;
count = 1;
while (System.IO.Directory.Exists(realFolder)) {
realFolder = folder + count;
count++;
}
// Create the folder
System.IO.Directory.CreateDirectory(realFolder);
}
function Update () {
// name is "realFolder/0005 shot.png"
var name = String.Format("{0}/{1:D04} shot.png", realFolder, Time.frameCount );
// Capture the screenshot
Application.CaptureScreenshot (name);
}
http://game.ceeger.com/Script/Application/Application.CaptureScreenshot.html
function OnGUI(){
if(GUI.Button(Rect(Screen.width*0.5-50,Screen.height*0.5-50,100,100),"screen")){
Application.CaptureScreenshot("Screenshot.png");
}
}
【c#】
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图片被存在了当前工程的子目录下了。
===========================================================
另外的方法
function ScreenshotEncode()
{
// wait for graphics to render
yield WaitForEndOfFrame();
// create a texture to pass to encoding
var texture:Texture2D = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
// put buffer into texture
texture.ReadPixels(Rect(0.0, 0.0, Screen.width, Screen.height), 0.0, 0.0);
texture.Apply();
// split the process up–ReadPixels() and the GetPixels() call inside of the encoder are both pretty heavy
yield;
// create our encoder for this texture
var encoder:JPGEncoder = new JPGEncoder(texture, 75.0);
// encoder is threaded; wait for it to finish
while(!encoder.isDone)
yield;
// save our test image (could also upload to WWW)
File.WriteAllBytes(Application.dataPath + “/../testscreen-” + count + “.jpg”, encoder.GetBytes());
count++;
}
//简便方法看下面:
function OnMouseDown() {
Application.CaptureScreenshot(“Screenshot.png”);
}
{
// wait for graphics to render
yield WaitForEndOfFrame();
// create a texture to pass to encoding
var texture:Texture2D = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
// put buffer into texture
texture.ReadPixels(Rect(0.0, 0.0, Screen.width, Screen.height), 0.0, 0.0);
texture.Apply();
// split the process up--ReadPixels() and the GetPixels() call inside of the encoder are both pretty heavy
yield;
// create our encoder for this texture
var encoder:JPGEncoder = new JPGEncoder(texture, 75.0);
// encoder is threaded; wait for it to finish
while(!encoder.isDone)
yield;
// save our test image (could also upload to WWW)
File.WriteAllBytes(Application.dataPath + "/../testscreen-" + count + ".jpg", encoder.GetBytes());
count++;
}
//简便方法看下面:
function OnMouseDown() {
Application.CaptureScreenshot("Screenshot.png");
}
Unity3d 截取窗体图片并保存
// The folder we place all screenshots inside.// If the folder exists we will append numbers to create an empty folder.
var folder = "ScreenshotFolder";
var frameRate = 25; //每秒25帧。
private var realFolder = "";
function Start () {
// Set the playback framerate!
// (real time doesn't influence time anymore)
Time.captureFramerate = frameRate;
// Find a folder that doesn't exist yet by appending numbers!
realFolder = folder;
count = 1;
while (System.IO.Directory.Exists(realFolder)) {
realFolder = folder + count;
count++;
}
// Create the folder
System.IO.Directory.CreateDirectory(realFolder);
}
function Update () {
// name is "realFolder/0005 shot.png"
var name = String.Format("{0}/{1:D04} shot.png", realFolder, Time.frameCount );
// Capture the screenshot
Application.CaptureScreenshot (name);
}
unity3d 屏幕截图多种写法
http://game.ceeger.com/Script/Application/Application.CaptureScreenshot.htmlfunction OnGUI(){
if(GUI.Button(Rect(Screen.width*0.5-50,Screen.height*0.5-50,100,100),"screen")){
Application.CaptureScreenshot("Screenshot.png");
}
}
【c#】
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图片被存在了当前工程的子目录下了。
===========================================================
另外的方法
function ScreenshotEncode()
{
// wait for graphics to render
yield WaitForEndOfFrame();
// create a texture to pass to encoding
var texture:Texture2D = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
// put buffer into texture
texture.ReadPixels(Rect(0.0, 0.0, Screen.width, Screen.height), 0.0, 0.0);
texture.Apply();
// split the process up–ReadPixels() and the GetPixels() call inside of the encoder are both pretty heavy
yield;
// create our encoder for this texture
var encoder:JPGEncoder = new JPGEncoder(texture, 75.0);
// encoder is threaded; wait for it to finish
while(!encoder.isDone)
yield;
// save our test image (could also upload to WWW)
File.WriteAllBytes(Application.dataPath + “/../testscreen-” + count + “.jpg”, encoder.GetBytes());
count++;
}
//简便方法看下面:
function OnMouseDown() {
Application.CaptureScreenshot(“Screenshot.png”);
}
相关文章推荐
- unity3d 动态改变模型大小、方向(展示必用)
- Unity3d 场景打包与加载
- unity3d 动态改变模型大小
- unity3d 资源文件从MAX或者MAYA中导出的注意事项
- Unity3d 调用外部视频
- Unity3D 自动光照 shader
- Unity 中的向量的 相关使用1
- 全面理解Unity加载和内存管理机制之二:进一步深入和细节
- Unity5中优化VR 应用的12个技巧
- (二十)unity4.6得知Ugui中国文献-------另外-InputModules
- Unity调用C++中DLL文件
- Unity3d中所有特殊的文件夹
- Unity3d中所有特殊的文件夹
- Unity3D 提高视频movie视频播放的质量
- unity3d 播放视频
- unity3d 定时循环
- unity3d assetbundle打包策略
- Unity AssetBundle爬坑手记
- Unity脚本周期关系
- Unity3D 事件回调