unity3d 屏幕截图多种写法

本文介绍了如何在Unity中使用不同方法进行屏幕截图,包括直接调用Application.CaptureScreenshot方法及通过纹理编码实现更复杂的截图功能。
function 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”);
 
}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值