我有一个问题!
我只是想要,只是...使用EncodeToJPG()函数将Texture2D转换为Byte[] !
我的工作区是 Unity 和 C# Script,+ OpenCvSharp。
也许你认为这很容易,但它有一些问题。
此脚本使用 OpenVR(HTC VIVE)。
无论如何,这是我的来源。
var source = SteamVR_TrackedCamera.Source(undistorted);
//Receive texture data from VR.
texture = source.texture;
//Debug.Log(source.texture.width + "/" + source.texture.height);
//size : 612 /460
if (texture == null)
{
return;
}
//Input texture data into material, and it's in unity (quad GameObject).
//this G.O print display like camera
material.mainTexture = texture;
//here is my src, I want to save Image but texture.EncodeToJPG has some error.
Cv2.ImShow("_Texture ...", Mat.FromImageData(texture.EncodeToJPG()));
Cv2.ImWrite(SavePath+ "Image.jpg", Mat.FromImageData(texture.EncodeToJPG()));
而且……有问题。变量纹理是异常Texture2D类型。
if (_texture == null)
{
_texture = Texture2D.CreateExternalTexture((int)header.nWidth, (int)header.nHeight, TextureFormat.RGBA32, false, false, nativeTex);
//_texture = new Texture2D(612, 460, TextureFormat.RGBA32, false);
uint width = 0, height = 0;
var frameBounds = new VRTextureBounds_t();
if (trackedCamera.GetVideoStreamTextureSize(deviceIndex, frameType, ref frameBounds, ref width, ref height) == EVRTrackedCameraError.None)
{
// Account for textures being upside-down in Unity.
frameBounds.vMin = 1.0f - frameBounds.vMin;
frameBounds.vMax = 1.0f - frameBounds.vMax;
this.frameBounds = frameBounds;
}
}
else
{
_texture.UpdateExternalTexture(nativeTex);
//_texture.Apply();
}
_texture是由函数CreateExternalTexture创建的,它具有名为 nativeTex 的 Intptr 类型的参数。
我不知道我该怎么办?
+++编辑!错误显示 +++