有人可以解释下面两个例子之间的区别:
在Unity中预构建,将文件(从test.jpg重命名为test.jpg.bytes)拖动到定义为TextAsset(imageAsset)的插槽,然后使用以下代码:
private byte[] PrepareImageFile()
{
int width = Screen.width;
int height = Screen.height;
var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.LoadImage(imageAsset.bytes);
tex.Apply();
byte[] bytes = tex.EncodeToPNG();
Destroy(tex);
return bytes;
}
在Android平板电脑上构建后,传入图库图像路径(aPath),然后使用此代码:
private byte[] PrepareTheFile(string aPath)
{
byte[] data = File.ReadAllBytes(aPath);
int width = Screen.width;
int height = Screen.height;
var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.LoadImage(data);
tex.Apply();
byte[] bytes = tex.EncodeToPNG();
Destroy(tex);
return bytes;
}
我知道它们不同的原因是当图像被发送到面部识别API(使用字节)时,#1返回准确的结果(9/10已识别),但#2返回不准确的结果(仅识别1/10)正确)。
没有错误,图片必须到达目的地进行分析,因为10个人中有1人被正确识别。
public void GrabImage()
{
NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
{
if (path != null)
{
texture = new Texture2D(300, 300, TextureFormat.RGB24, false);
texture.LoadImage(File.ReadAllBytes(path));
Debug.Log(_celebTextAttributes.text + "W:" + texture.width + " x H:" + texture.height);
texture.Apply();
_celebTextAttributes.SetText("Path: " + path);
imagePath = path;
}
}, "Select an image from", "image/png");
_celebImage.GetComponent<Renderer>().material.mainTexture = texture;
}
任何帮助?