- Home /
Problems in conversion between byte and texture2D
I can see something in tex2 but is an image with strange colums. It can be a problem of texture format?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class webcam : MonoBehaviour {
public RawImage rawImage;
WebCamTexture wc;
public Texture2D tex;
public byte[] rawData;
public RawImage test;
private Texture2D tex2;
// Use this for initialization
void Start () {
wc = new WebCamTexture(320,240);
wc.Play();
//img.texture = wc;
rawImage.texture = wc;
tex = new Texture2D(wc.width, wc.height);
tex.SetPixels(wc.GetPixels());
tex.Apply();
tex2 = new Texture2D(320, 240, TextureFormat.RGB24, false);
}
// Update is called once per frame
void Update () {
//rawData = tex.EncodeToPNG();
rawData = tex.GetRawTextureData();
GameObject go = GameObject.FindGameObjectWithTag("test");
test = (RawImage)go.GetComponent<RawImage>();
tex2.LoadRawTextureData(rawData);
tex2.Apply();
test.material.mainTexture = tex2;
test.texture = tex2;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612125125im_/https://answers.unity.com/themes/thub/images/avi.jpg)