【小超_U3D】Unity截屏分享调用Android
来源:互联网 发布:简单快递单打印软件 编辑:程序博客网 时间:2024/04/29 04:00
方法一:在unity的API中,unity给我们提供了一个现成的API : Application.CaptureScreenshot(imagename)。但是这个API虽然简单,在PC、mac运用没有多大的影响,但是如果是在移动平台上使用的话就显得相当的吃力,因为它会消耗我们很大的CUP,所以你在移动端使用它截屏的时候会发现很长一段的卡顿现象。但是不得不说使用起来非常的方便,但是在我们使用这个API截图后的截图存放在哪儿呢?很多新朋友可能不是很清楚,当然不同的平台它的存放路径是有差别的。下面是各个平台的截图存放路径:
Application.CaptureScreenshot(screencapture.png) if(Application.platform==RuntimePlatform.Android || Application.platform==RuntimePlatform.IPhonePlayer) imagePath=Application.persistentDataPath; else if(Application.platform==RuntimePlatform.WindowsPlayer) imagePath=Application.dataPath; else if(Application.platform==RuntimePlatform.WindowsEditor) { imagePath=Application.dataPath; imagePath= imagePath.Replace("/Assets",null); } imagePath = imagePath + "/screencapture.png";
如果你想要你的游戏中显示你截图的缩略图,那么这种方法不是一个好方法,因为你要用 WWW去加载你刚才的截图,这会消耗你一部分的时间。
方法二:通过读取屏幕缓存然后转化为Png图片进行截图。(当然截图存储路径你可以自己设置)
IEnumerator GetCapture() { yield return new WaitForEndOfFrame(); int width = Screen.width; int height = Screen.height; Texture2D tex = new Texture2D(width,height,TextureFormat.RGB24,false); tex.ReadPixels(new Rect(0,0,width,height),0,0,true); byte[] imagebytes = tex.EncodeToPNG();//转化为png图 tex.Compress(false);//对屏幕缓存进行压缩 File.WriteAllBytes(Application.persistentDataPath + "/screencapture.png",imagebytes);//存储png图 }StartCoroutine(GetCapture());在安卓中调用方法:void getImage(){//路径名称,通过这个路径去取的截取图片的位置string msg=Application.persistentDataPath+ "/screencapture.png";using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {using (AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity")) {//在android里面调用启动的Activityjo.Call ("shareBySms", new object[] {msg});//传值到android 可用作分享}}}
android里面的分享很多 在这里就不做介绍
0 0
- 【小超_U3D】Unity截屏分享调用Android
- 【小超_U3D】Android环境的配置和Unity导出APK
- 【小超_U3D】Unity打出Android包,运行报错解决方案
- 【小超_U3D】Unity3D占用内存太大的解决方法
- 【小超_U3D】Unity3D对陀螺仪的使用
- Unity调用Android
- Unity调用Android
- unity 调用android函数
- unity 调用android函数
- Unity调用Android
- Unity调用Android
- unity 调用android函数
- Unity调用Android
- Unity调用Android录音
- Unity调用Android API
- Unity调用android
- Unity 调用Android方法
- unity调用android
- 优游平台总代娱乐总代【总代Q941494533】萍
- 优游平台总代和优游平台总代【总代Q941494533】棺
- http://dongxi.douban.com/article/1322502/
- 优游平台总代最新的网址【总代Q941494533】亲
- 优游平台怎么找总代【总代Q941494533】盖
- 【小超_U3D】Unity截屏分享调用Android
- tomcat7.0 内存配置 和 端口配置
- Email,Tel 等的正则表达式
- zoj 3228 ac自动机
- [济南考勤机专题]考勤机类型(六)生物识别考勤机
- 将扯淡的时间都用来做有意义的事
- 关于squid对同一个url缓存多个文件的资料记录
- 哮喘专题讨论会
- 通过ddms无法检查的内存泄漏如何查