- Home /
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!
Answer by whydoidoit · Sep 30, 2012 at 10:55 AM
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.
Do you have an example? C# preferred, but I can translate from JS if needed.
Your answer
Follow this Question
Related Questions
Get multiple images from online server and download them to android app 1 Answer
How to cut an image at an angle from the center? 0 Answers
!texture.texture error 0 Answers
How to grab POST image data from WWWForm on server? 1 Answer
How to upload files for use in built game from user's computer? 0 Answers