【Unity】关于ScreenCapture.CaptureScreenshot截屏的尝试

利用Unity提供函数"ScreenCapture"可以屏幕截取,不过只能截全屏,不区分层级,屏幕内显示的会全部截取下来,与手机截屏功能比较类似,实用性不大 ···

下面是一组简单测试的数据:

        //屏幕尺寸: 720*1280

        //保存截图到本地

        //ScreenCapture.CaptureScreenshot(截屏图片保存路径);
        //后缀名, 需要自定义后缀名,png、jpg等图片格式,也可以是其他格式,比如txt,不过保存的是一堆乱码
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName01.png");          //尺寸: 512*1024      大小: 341.4KB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName0a.jpg");          //尺寸: 512*1024      大小: 341.4KB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName0b.txt");          //尺寸: ***           大小: ***

        //ScreenCapture.CaptureScreenshot(截屏图片保存路径, 分辨率指数);
        //分辨率指数或分辨率影响参数,测试发现,数值应为正整数,<=0时,默认为1,同时也有上限,不知跟截图对象有没有关系,测试发现是有1跟2有区别
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName02.png", 0);       //尺寸: 512*1024      大小: 341.4KB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName03.png", -1);      //尺寸: 512*1024      大小: 341.4KB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName04.png", 1);       //尺寸: 512*1024      大小: 341.4KB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName05.png", 2);       //尺寸: 1024*2048     大小: 1.3MB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName06.png", 3);       //尺寸: 1024*2048     大小: 1.3MB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName07.png", 4);       //尺寸: 1024*2048     大小: 1.3MB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName08.png", 5);       //尺寸: 1024*2048     大小: 1.3MB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName09.png", 10);      //尺寸: 1024*2048     大小: 1.3MB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName10.png", 20);      //尺寸: 1024*2048     大小: 1.3MB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName11.png", 50);      //尺寸: 1024*2048     大小: 1.3MB

        //ScreenCapture.CaptureScreenshot(截屏图片保存路径, 截屏方式);
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName12.png", ScreenCapture.StereoScreenCaptureMode.BothEyes);      //尺寸: 512*1024      大小: 341.4KB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName13.png", ScreenCapture.StereoScreenCaptureMode.BothEyes);      //尺寸: 512*1024      大小: 341.4KB
        ScreenCapture.CaptureScreenshot(Application.dataPath + "/fileName14.png", ScreenCapture.StereoScreenCaptureMode.BothEyes);      //尺寸: 512*1024      大小: 341.4KB

        //获取 Texture2D 截图,参数同上
        Texture2D texture2D01 = ScreenCapture.CaptureScreenshotAsTexture();
        Texture2D texture2D02 = ScreenCapture.CaptureScreenshotAsTexture(1);
        Texture2D texture2D03 = ScreenCapture.CaptureScreenshotAsTexture(ScreenCapture.StereoScreenCaptureMode.BothEyes);

        //获取 RenderTexture 截图
        RenderTexture renderTexture = new RenderTexture(720, 1280, 1);
        ScreenCapture.CaptureScreenshotIntoRenderTexture(renderTexture);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萧然CS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值