Need help uploading an image.

Hey everyone, first time poster, so I apologize if I make a mistake. There is a part of my app in which a user will start their front-facing camera to take a picture. After a user takes a picture (using WebCamTexture.Stop) the app takes the WebCamTexture’s texture and assigns it to a material in my assets folder.

Now, this is where I need help. I would like to know how (if it’s at all possible) to take the image that was captured (which is now on the material), and save it to a local file or to upload it to a server. I have tried using (Texture2D)Resources.Load(mat) but I keep getting an “InvalidCastException: Cannot cast from source type to destination type.” I assume that means that I cannot convert a material into a Texture2D. Does anyone have any thoughts on how to accomplish this?

Again, I apologize if my question is a little confusing or vague, but it is 1:16am and I’m about to go to bed. I hope to hear from someone when I wake up in the morning.

Thanks everyone!

You are going to want to create a Texture2D with the same dimensions as the WebCamTexture and then use GetPixels and SetPixels to move the data from the WebCamTexture to the Texture2D - at which point you will be able to call Texture2D.EncodeToPNG to get your file for upload or local storage.