zoukankan      html  css  js  c++  java
  • unity3d屏幕截图功能

    http://game.ceeger.com/Script/Application/Application.CaptureScreenshot.html

    [java] 
    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”);
    }

  • 相关阅读:
    NoSQL数据库:Java开源项目Neo4j简介
    EPOLL和IOCP比较
    CString&CStringA&CStringW之间的相互转换
    CString和CStringA之间的转换
    Windows IOCP模型与Linux EPOLL模块之比较
    OCP-1Z0-053-V13.02-708题
    OCP-1Z0-053-V13.02-709题
    OCP-1Z0-053-V12.02-342题
    OCP-1Z0-053-V12.02-341题
    OCP-1Z0-053-V13.02-706题
  • 原文地址:https://www.cnblogs.com/oldman/p/2628799.html
Copyright © 2011-2022 走看看