Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
截屏。截屏图像看起来不像屏幕。显示时为半透明(Unity 3D、Android)_Android_Unity3d_Image Processing_Textures_Screen Capture - Fatal编程技术网

截屏。截屏图像看起来不像屏幕。显示时为半透明(Unity 3D、Android)

截屏。截屏图像看起来不像屏幕。显示时为半透明(Unity 3D、Android),android,unity3d,image-processing,textures,screen-capture,Android,Unity3d,Image Processing,Textures,Screen Capture,[编辑以在底部提供附加信息/部分答案] 任何关于如何解决此问题的建设性意见都将受到赞赏 我遵循本教程,使用Unity的Screencapture.Capturescreenshot()方法拍摄并显示屏幕截图 在显示器上,我的屏幕截图(3D空间中的基本立方体)显示为半透明。有人知道我为什么以及如何修复它,使它显示一个真实的屏幕截图吗?当我在这里拍摄屏幕快照时,我用另一部手机拍摄了我的实际屏幕(抱歉,有点模糊;立方体正在移动): 以及显示的屏幕快照的图片。请注意它的半透明程度: 这是显示的代码。

[编辑以在底部提供附加信息/部分答案]

任何关于如何解决此问题的建设性意见都将受到赞赏

我遵循本教程,使用Unity的Screencapture.Capturescreenshot()方法拍摄并显示屏幕截图

在显示器上,我的屏幕截图(3D空间中的基本立方体)显示为半透明。有人知道我为什么以及如何修复它,使它显示一个真实的屏幕截图吗?当我在这里拍摄屏幕快照时,我用另一部手机拍摄了我的实际屏幕(抱歉,有点模糊;立方体正在移动):

以及显示的屏幕快照的图片。请注意它的半透明程度:

这是显示的代码。它将.png文件转换为纹理,从纹理生成精灵,并在画布上显示精灵。我的画布在检查器中设置为默认参数

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using System.IO;
 
 public class ScreenshotPreview : MonoBehaviour {
     
     public GameObject canvas;
     string[] files = null;
     int whichScreenShotIsShown= 0;
 
     // Use this for initialization
     void Start () {
         files = Directory.GetFiles(Application.persistentDataPath + "/", "*.png");
         if (files.Length > 0) {
             GetPictureAndShowIt ();
         }
     }
 
     void GetPictureAndShowIt()
     {
         string pathToFile = files [whichScreenShotIsShown];
         Texture2D texture = GetScreenshotImage (pathToFile);
         Sprite sp = Sprite.Create (texture, new Rect (0, 0, texture.width, texture.height),
             new Vector2 (0.5f, 0.5f));
         canvas.GetComponent<Image> ().sprite = sp;
     }
 
     Texture2D GetScreenshotImage(string filePath)
     {
         Texture2D texture = null;
         byte[] fileBytes;
         if (File.Exists (filePath)) {
             fileBytes = File.ReadAllBytes (filePath);
             texture = new Texture2D (2, 2, TextureFormat.RGB24, false);
             texture.LoadImage (fileBytes);
         }
         return texture;
     }
 }
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用UnityEngine.UI;
使用System.IO;
公共类截图预览:MonoBehavior{
公共游戏对象画布;
string[]files=null;
int,其中screenshotisshown=0;
//用于初始化
无效开始(){
files=Directory.GetFiles(Application.persistentDataPath+“/”,“*.png”);
如果(files.Length>0){
GetPictureAndShowIt();
}
}
void GetPictureAndShowIt()
{
字符串pathToFile=文件[whichScreenShotIsShown];
Texture2D纹理=GetScreenshotImage(路径文件);
Sprite sp=Sprite.Create(纹理,新矩形(0,0,纹理.width,纹理.height),
新矢量2(0.5f,0.5f));
canvas.GetComponent().sprite=sp;
}
Texture2D GetScreenshotImage(字符串文件路径)
{
Texture2D texture=null;
字节[]文件字节;
如果(File.Exists(filePath)){
fileBytes=File.ReadAllBytes(文件路径);
纹理=新纹理2d(2,2,TextureFormat.RGB24,false);
texture.LoadImage(文件字节);
}
返回纹理;
}
}

其他信息:

所以我的想法是,问题要么在于捕捉,要么在于显示。我意识到我可以在Android文件中查看保存的.png文件,看看它们是什么样子,然后再将它们拉回到应用程序中显示


结果如何.png看起来很完美。所以这只是显示的问题。我还没有解决整个问题,但现在我知道使用Unity的Screencapture.Capturescreenshot方法可以完美地捕获屏幕。

结果是,我的面板在第二个场景中的“alpha”值约为50%,在alpha值中约为127。为了精确显示屏幕上拍摄的图像,alpha必须为255,表示0%的透明度。通常,许多人希望UI元素具有一定程度的透明度,以便可以看到UI元素背后的主场景。然而,对于查看屏幕截图,我不想要透明度。因此=>选择层次结构中的面板。转到“检查员”中的“颜色质量”。双击。然后将Alpha值设置为255

如果您没有只用于查看屏幕快照的专用场景,并且希望在单个场景中更改alpha值,则可以使用脚本进行更改。在我的例子中,我可以将alpha永久设置为255,因为那个场景的唯一用途,实际上那个面板的唯一用途,就是显示屏幕截图。

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using System.IO;
 
 public class ScreenshotPreview : MonoBehaviour {
     
     public GameObject canvas;
     string[] files = null;
     int whichScreenShotIsShown= 0;
 
     // Use this for initialization
     void Start () {
         files = Directory.GetFiles(Application.persistentDataPath + "/", "*.png");
         if (files.Length > 0) {
             GetPictureAndShowIt ();
         }
     }
 
     void GetPictureAndShowIt()
     {
         string pathToFile = files [whichScreenShotIsShown];
         Texture2D texture = GetScreenshotImage (pathToFile);
         Sprite sp = Sprite.Create (texture, new Rect (0, 0, texture.width, texture.height),
             new Vector2 (0.5f, 0.5f));
         canvas.GetComponent<Image> ().sprite = sp;
     }
 
     Texture2D GetScreenshotImage(string filePath)
     {
         Texture2D texture = null;
         byte[] fileBytes;
         if (File.Exists (filePath)) {
             fileBytes = File.ReadAllBytes (filePath);
             texture = new Texture2D (2, 2, TextureFormat.RGB24, false);
             texture.LoadImage (fileBytes);
         }
         return texture;
     }
 }