C#unity脚本使用库UnityNativeGallery在android库中获取并保存屏幕截图
实际上我正在尝试截取并将其保存到Android库中,我正在使用一个开源库来实现“Unity Native Gallery”我的代码如下:
NativeGallery.Permission permission = NativeGallery.CheckPermission();
if (permission == NativeGallery.Permission.Granted) {
Debug.Log("May proceed");
}
else {
Debug.Log("Not allowed");
}
// Output ==> "May Proceed"
Debug.Log("Path is "+NativeGallery.GetSavePath("GalleryTest","My_img_{0}.png"));
//Output ==> /storage/emulated/0/DCIM/GalleryTest/My_img_1.png
Texture2D ss = new Texture2D( Screen.width, Screen.height, TextureFormat.RGB24, false );
ss.ReadPixels( new Rect( 0, 0, Screen.width, Screen.height ), 0, 0 );
ss.Apply();
Debug.Log("Secondlast");
permission = NativeGallery.SaveImageToGallery( ss, "GalleryTest", "My_img_{0}.png" ) ;
Debug.Log("Done screenshot");
但是我从来没有保存屏幕截图,当我看到控制台时,我得到了两个重要的日志
1.我的调试日志“SecondLast”在控制台上打印但不是最后一个“Done screenshot”
2.有一个异常打印“UnauthorizedAccessException:访问路径”/storage/emulated/0/DCIM/GalleryTest/My_img_1.png“被拒绝.”
重要的一点: – 我已经在统一播放器设置中将写入权限设置为外部(SDCard). (实际上我尝试使用“内部”和“外部”两种设置)