Saving a Texture2D as .jpg in a folder (c#)
Hey,
How can I change the format of an existing texture from Texture2D to .jpg and save it in a folder like for example (C:\xampp\htdocs)?
Thank you in advance!!
http://docs.unity3d.com/ScriptReference/Texture2D.EncodeToJPG.html
// to store image
var bytes = texture.EncodeToPNG ();
var path = System.IO.Path.Combine(Application.persistentDataPath, fileName + ".png");
System.IO.File.WriteAllBytes (path, bytes);
// To get image
var path = System.IO.Path.Combine (Application.persistentDataPath, fileName+ ".png");
var bytesRead = System.IO.File.ReadAllBytes (path);
Texture2D myTexture = new Texture2D (1024, 1024);
myTexture.LoadImage (bytesRead);
Hope for the best
Thank you!! But unfortunately it does not recognize the .EncodeToPNG! Is it because I'm working in an Editor-Script?
Thank you Umresh but I found a differen solution for my problem! I took the source image (not the texture2d) of a material and copied it in a new folder.
string BumpName = oldBump.name + ".jpg";
string sourceFileBump = System.IO.Path.Combine("Assets/Resources/Object/"+ SelectedObject.name +".fbm/", BumpName);
string destFileBump = System.IO.Path.Combine("C:/xampp/htdocs/$$anonymous$$asterProjekt", BumpName);
System.IO.File.Copy(sourceFileBump, destFileBump, true);
Your answer

Follow this Question
Related Questions
Programmatically "Stamping" an image on a Texture2D. 0 Answers
Import Image then get all Pixels 0 Answers
Button calls itself numerous times 0 Answers
Alpha for "Fade" render mode ignored when loading PNG texture dynamically 0 Answers
Textures from a texture atalas turning black in the distance 0 Answers