- Home /
Save a Texture2D for android
I am accessing an image from android device gallery in unity made game and then assigning that image on my object as a texture2D. What I want now is to save that image(texture) so next time I start the game or the same scene I still have that image(texture) so I can use it on the same object. I can save the path to the image and load that image next time again from the gallery, but I don't want to do that because it is kind a slow for me. Is there any solution to saving the image locally in the application folder or something similar.
Thanks
no help. Please any one guide me to the right direction. Thanks
Here is cross platform solution to save texture to gallery. http://unitydevelopers.blogspot.in/2014/06/capture-and-save-to-camera-roll-and.html
There are 2 versions so you have freedom to select as per your need.
Answer by shinevision · Jan 25, 2018 at 12:30 AM
Mmm. i've never tried saving an image. But you could try this:
File.WriteAllBytes("Path/folder/MyImage.png",bytes);
You would somehow have to convert the image to a byte array.
Sorry if this isnt the answer you where looking for. But goodluck!
EDIT: you can use this to convert it to bytes:
byte[] _bytes =_texture.EncodeToPNG();
Source: (https://answers.unity.com/questions/1331297/how-to-save-a-texture2d-into-a-png.html)
Your answer
Follow this Question
Related Questions
Download Image to a new album (Android) 0 Answers
Passing texture to android plugin 0 Answers
pick image from android gallery 3 Answers
How to load image from android gallery 0 Answers