Unity安卓Android与iOS保存图片并显示在相册
2017-01-23 10:26
811 查看
1.安卓
安卓手机有可能有SD卡 有可能没,如果有SD卡,直接用unity的截屏API或者Application的路径会同时保存,
下面写存在手机内部。
哈哈哈 忘记给jar了
链接:http://pan.baidu.com/s/1gfggIav 密码:3nld
2.iOS
参考http://blog.csdn.net/wf_unity/article/details/22087643
安卓手机有可能有SD卡 有可能没,如果有SD卡,直接用unity的截屏API或者Application的路径会同时保存,
下面写存在手机内部。
//存储路径destination 图片名screenshotFilename //PhotoCam摄像头 RenderTexture currentRT = RenderTexture.active; RenderTexture.active = PhotoCam.targetTexture; PhotoCam.Render(); Texture2D image = new Texture2D((int)Screen.width, (int)Screen.height); image.ReadPixels(new Rect(0, 0, (int)Screen.width, (int)Screen.height), 0, 0); image.Apply(); RenderTexture.active = currentRT; byte[] bytes = image.EncodeToPNG(); string destination = "/storage/emulated/0/DCIM/ARPhoto"; //判断目录是否存在,不存在则会创建目录 if (!Directory.Exists (destination)) { Directory.CreateDirectory (destination); } string Path_save = destination+"/" + screenshotFilename; //存图片 System.IO.File.WriteAllBytes(Path_save, bytes); 上面完成了图片的保存 但是不会出现在相册,下面让图片出现在相册(更新) //**************方法1 屏幕截图,保存路径*****************// Debug.Log("Android platform detected"); string androidPath = "/storage/emulated/0/DCIM/ARPhoto" + "/" + screenshotFilename; photoPath = androidPath; string path = androidPath; string pathonly = Path.GetDirectoryName(path); Directory.CreateDirectory(pathonly); AndroidJavaClass obj = new AndroidJavaClass("com.ryanwebb.androidscreenshot.MainActivity"); while(!photoSaved) { photoSaved = obj.CallStatic<bool>("scanMedia", path); yield return new WaitForSeconds(.1f); } //**********************************************//
哈哈哈 忘记给jar了
链接:http://pan.baidu.com/s/1gfggIav 密码:3nld
2.iOS
参考http://blog.csdn.net/wf_unity/article/details/22087643
相关文章推荐
- Unity中关于保存图片到Android/IOS相册中的问题
- Android 保存图片到相册无法显示的问题
- android保存图片到本地并可以在相册中显示出来
- Unity调用Android保存图片到相册
- Android 保存图片到相册无法显示的问题
- Android 拍照以及一些常用的处理,例如将图片显示到相册(包含了安卓系统6.0以上调用相机的处理)
- Android相机、相册获取图片显示并保存到SD卡
- Android相机、相册获取图片显示并保存到SD卡
- [置顶] 在unity中将图片保存在移动平台下(Android和IOS)
- android如何将生成的图片保存至手机相册并显示出来
- android保存图片到本地并可以在相册中显示出来
- android保存图片后相册中不能马上显示的解决、!
- iOS拍照 相册选取 保存PNG图片到Documents下,并利用UICollectionView显示出来
- 史上最强Android 开启照相或者是从本地相册选中一张图片以后先裁剪在保存并显示的讲解附源码
- android保存图片到本地并可以在相册中显示出来
- Android 保存图片到相册无法显示的问题
- Android相机、相册获取图片显示并保存到SD卡 - Ryan's zone 的案例
- android保存图片到本地并可以在相册中显示出来
- android 保存图片到相册并正常显示
- 史上最强Android 开启照相或者是从本地相册选中一张图片以后先裁剪在保存并显示的讲解附源码i