我在Unity工作中遇到了一些問題,我試圖從Webcam紋理中獲取圖像,並將其保存在一個字節[]中。問題出現在我顯示圖像時,看不到正確的圖像,它看起來像某種類型的網格網格。我認爲問題在於我用來傳遞像素。我希望你能幫助我。 webcamtexture的圖像問題
void Update()
{
//texto.text = texto.text + width +"/"+ height + "/" + ini.ToString()+ " mal: "+ testo().ToString()+ " SizeIMG: "+ imgData.Length + " NUEVO: "+ nuevo +"\n";
imgData = null;
imgData = new byte[width * height * 3];
resultado = null;
resultado = new byte[width * height * 3];
color = webcam.GetPixels32();
for (int i = 0; i < color.Length; i += 3)
{
imgData[(i * 3)] = color[i].r;
imgData[(i * 3) + 1] = color[i].g;
imgData[(i * 3) + 2] = color[i].b;
}
color = null;
//video(imgData, resultado);
//ProcessFrame(imgData, resultado, 0, 0, 0,0, nuevo);
nuevo = false;
textura2 = new Texture2D(width, height, TextureFormat.RGB24, false);
textura2.LoadRawTextureData(imgData);
textura2.Apply();
//Left IMAGE
renderer.material.mainTexture = textura2;
textura2 = null;
RightImage.GetComponent<Renderer>().material.mainTexture = webcam;
if (kont == 30)
{
texto.text = "";
kont = 0;
}
kont++;
Resources.UnloadUnusedAssets();
}
你確定圖像是每像素3位而不是4嗎? –
我認爲它是3位,RGB格式,但我不確定。 –
btw,圖像尺寸和color.length的值是什麼? –