PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > Unity3D教程 > 正文

    关于Unity截图

    作者:张志勇来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:那个简单的截图方式我这里用的老出错,不清楚什么原因,等什么时候找到原因了我重新改这篇文章Rect t=new Rect(new Vector2(1,1),new V...

    那个简单的截图方式我这里用的老出错,不清楚什么原因,等什么时候找到原因了我重新改这篇文章

    Rect t=new Rect(new Vector2(1,1),new Vector2(100,100));

    public Texture2D i;

    void Update(){

         if (Input.GetMouseButtonDown(0)) {

             Texture2D y= CaptureScreenshot2(t);

              i = y;

         } 

     }

    Texture2D CaptureScreenshot2(Rectrect)

    {

    Texture2D screenShot=new Texture2D((int)rect.width,(int)rect.height,TextureFormat.RGB24,false);

    //读取屏幕像素

    screenShot.ReadPixels(rect,0,0);

    screenShot.Apply();

    //纹理数据组成一个png图片

    byte[] bytes=screenShot.EncodeToPNG();

    string filename=Application.dataPath+"/Screenshot.png";

    System.IO.File.WriteAllBytes(filename,bytes);

    return screenShot;

    }

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-130-5982-1.html
    相关热词搜索: