- Home /
Question by
Addyarb · Jan 13, 2016 at 08:40 PM ·
spritewebcamtexturepng
PNG/Sprite Creation Works on PC/Mac But Not On Android
Hi Unity!
I've been at this for hours now, and have tried many different methods. This includes using the WWW class to get directly from a path.
What I'm trying to do (and have accomplished on in-editor):
Take picture with WebCamTexture
Convert it to a sprite
Show it in the editor
That's all! I can't seem to find a method that works for Android as hard as I've tried.
Any help would be appreciated!
if (Application.platform == RuntimePlatform.Android) {
Texture2D photo = new Texture2D (webCamTexture.width, webCamTexture.height);
photo.SetPixels (webCamTexture.GetPixels ());
photo.Apply ();
//Encode to a PNG
byte[] bytes = photo.EncodeToPNG ();
//Write out the PNG.
File.WriteAllBytes (Application.persistentDataPath + "photo.png", bytes);
debug.text = ("Image saved to" + Application.persistentDataPath + "photo.png");
orderingPreview.sprite = Sprite.Create (photo, new Rect (0, 0, 1080, 720), new Vector2 (0.5f, 0.5f));
initialPreview.sprite = Sprite.Create (photo, new Rect (0, 0, 1080, 720), new Vector2 (0.5f, 0.5f));
}
Comment
$$anonymous$$issing slash?
File.WriteAllBytes (Application.persistentDataPath + "/photo.png", bytes);
Your answer
Follow this Question
Related Questions
Dealing with PNG's in the project 0 Answers
Best texture compression: TinyPNG + Unity sprite Packer? 1 Answer
Rendering an HD PNG off-screen? 0 Answers
How can I improve my PNG sprites? 1 Answer
Render WebCamTexture to Sprite? 0 Answers