Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Tasarran · May 16, 2012 at 06:01 PM · texturesavefile-ioio

What is the best way to save a modified texture to disk?

I have some textures that I want to do some SetPixel operations on, probably in an Editor script.

What is the best way to make the changes that I do in Unity stick? I want to take some of the load off my game, and put what I can in a pre-process.

I've seen some answers using the serializer to do this, would this work locally as well?

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tasarran · May 17, 2012 at 03:11 PM 0
Share

Anybody? Bueller... Bueller... Bueller...

avatar image flamy · May 17, 2012 at 03:56 PM 0
Share

hmm to save locally i usually encode it to png and then change it to string64 and save it in a text file

and and reverse the process to get the texture back, works fine for me!! but im not sure if this is wat you want.

avatar image Tasarran · May 17, 2012 at 04:01 PM 0
Share

That would probably work fine for me, any pointers to some how-to's?

avatar image flamy · May 17, 2012 at 04:03 PM 0
Share

im not on unity now let me prepare a rough on give me some time.

avatar image Tasarran · May 17, 2012 at 04:12 PM 1
Share

Is this what you mean? http://unity3d.com/support/documentation/ScriptReference/Texture2D.EncodeToPNG.html

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by flamy · May 17, 2012 at 04:44 PM

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class ImageSaver : MonoBehaviour {
     
     
     public Texture2D test;
     WWW www;
     
     void Start () {
         
         
         StartCoroutine( SaveTexture("bar","bar"));
         
     }
     
     public IEnumerator SaveTexture(string imageName,string saveAs)
     {
         Texture2D tex;
         byte[] byteArray;
         WWW www= new WWW("file://"+Application.dataPath+"//Resources//"+imageName+".png");
         
         yield return www;
         
         if(www.texture!=null)
         {
             print("success");
         }
         tex=www.texture;
         byteArray=tex.EncodeToPNG();
         
         string temp=Convert.ToBase64String(byteArray);
         
         PlayerPrefs.SetString(saveAs,temp);      /// save it to file if u want.
         PlayerPrefs.SetInt(saveAs+"_w",tex.width);
         PlayerPrefs.SetInt(saveAs+"_h",tex.height);
     }
     
     public Texture2D RetriveTexture(string savedImageName)
     {
         string temp=PlayerPrefs.GetString(savedImageName);
         
         int width=PlayerPrefs.GetInt(savedImageName+"_w");
         int height=PlayerPrefs.GetInt(savedImageName+"_h");
         
         byte[] byteArray= Convert.FromBase64String(temp);
         
         Texture2D tex = new Texture2D(width,height);
         
         tex.LoadImage(byteArray);
         return tex;
         
     }
     void Update () {
         
         test=RetriveTexture("bar");        
     
     }
 }


hey this is the tested code that works at my end. I am using www to load the texture inside the game because you cannot encode the texture imported inside unity, unless it is imported as ARGB32 or RGB24. so im loading it like an external image file and processing it. other than that it is pretty much explainable i guess.

PS: the texture shd be in resource folder.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image flamy · May 18, 2012 at 03:57 AM 0
Share

was that help full!!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Download images from url, save to device, load into UGUI 4 Answers

How to save and load `List myList`? 1 Answer

How to save and load node-based tree network data to a file? 1 Answer

Reading files on Android, 1 Answer

how to save a texture in background by looking at it. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges