- Home /
Texture to Texture2D
Hi, i've got Texture object and i need to read it's pixels but to do that i need to convert it to Texture2D and then use GetPixel. My question is how to convert it, i've tried (Texture2D)texture - it said "cannot cast from source type to destination type" texture as Texture2D - here i get null pointer exception
I think it's important, that texture is from WebCamTexture. Normal casting is not working.
Post the source, and post a copy from the console of the error message.
Answer by tanoshimi · Oct 02, 2014 at 09:27 PM
For webcam textures, you should be able to get a pixel array using GetPixels:
Color[] textureData = webcamTexture.GetPixels();
http://docs.unity3d.com/ScriptReference/WebCamTexture.GetPixels.html
tanoshimi that's what i needed, at start i was copying webcamtexture to texture and didn't check methods of webcamtexture.
THAN$$anonymous$$S!
Answer by smoggach · Oct 02, 2014 at 08:44 PM
Have you tried Texture3D ? You can read pixels from Texture3D as well. Texture is the base class.
Your answer
![](https://koobas.hobune.stream/wayback/20220613164254im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
convert Texture to Texture2D 4 Answers
SetPixels32 called with invalid number if pixels in the array 0 Answers
How to not see white background on texture 1 Answer
Unity changes pixel colors 2 Answers