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
0
Question by netkingZ · Apr 16, 2013 at 02:17 PM · texturesaveinstancepng

[solved] How to save instance of the texture?

With the following code I make sure that the revenues image from URL: [Javascript]

      var modys : boolean = false;
      var modus : boolean = false;
      private var windowRect : Rect =new Rect (Screen.width/2, 300, 220, 200);
      var Text : String = "";
      var TextName : String = "";
      var t : TextMesh;
      var nameTexture :  TextMesh;
      
    
     
 function OnMouseDown() {
 
     modys = !modys;
 }
 
     
     function OnGUI () {
     
     if(modys){
         // Register the window. Notice the 3rd parameter 
         windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window");
        
         }
     }
     
     // Make the contents of the window
    private function DoMyWindow (windowID : int) {
     
         GUILayout.Label("URL");
       Text = GUILayout.TextField (Text, 10000);
       GUILayout.Label("NameImage");
       TextName = GUILayout.TextField (TextName, 10000);
     
    
     
      if(GUILayout.Button ("Save")) {
                                                     
             t.text = Text;
             nameTexture.text = TextName;
             modys = false;
           
        
           Attive();
           Debug.Log(t.text);
                            
         }
         
        if(GUILayout.Button ("Close")) {
            modys = false;
        
        }
        
             
             
     }
     
    function Attive() {
  
      var url = t.text;
             // Create a texture in DXT1 format
                         renderer.material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
                     
                         // Start a download of the given URL
                       www = new WWW(url);
                         
                           yield www; 
                         
                         // assign the downloaded image to the main texture of the object
                         www.LoadImageIntoTexture(renderer.material.mainTexture);
                         
                    Debug.Log(url);
 
    }
    

I would like to save the instance of the image texture, how can I do? The system is activated by clicking on the plan that has the texture you will be asked to put a link and the name of the future texture. Then when you insert the texture is displayed in the plan, but has not yet created a new texture, so I need to create it, so I have to make sure that you save the texture taken from the URL, and that will give him the name chosen by the user , and subsequently recall to save to that particular GameObject (the plane) that determined texture.

Help me. Thank you.

Comment
Add comment · Show 3
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 netkingZ · Apr 16, 2013 at 08:27 PM 0
Share

Help me. Thank you.

avatar image netkingZ · Apr 17, 2013 at 05:19 PM 0
Share

up , please .

avatar image DeveshPandey · Nov 15, 2014 at 11:15 AM 0
Share

look on these plugin http://u3d.as/86U http://u3d.as/9Ee

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · Apr 17, 2013 at 06:00 PM

You can save the texture by doing:

 import System.IO;

 ...

 File.WriteAllBytes(Application.persistentDataPath + "/" + someFilename, someTexture.EncodePNG());
Comment
Add comment · Show 6 · 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 netkingZ · Apr 17, 2013 at 09:10 PM 0
Share

Thank you for taking my call. The error which gives me is the following:

BCE0017: The best overload for the method 'System.IO.File.WriteAllBytes (String, byte [])' is not compatible with the argument list '(System.Object, String)'.

Thanks for your help.

avatar image Dracorat · Apr 17, 2013 at 09:12 PM 0
Share

The arguments are actually reversed - the path part comes first. Just swap the arguments and you should be good...

 File.WriteAllBytes(Application.persistentDataPath + "/" + someFilename, (byte[]) someTexture.EncodePNG());
avatar image whydoidoit · Apr 17, 2013 at 09:13 PM 0
Share

Good point

avatar image netkingZ · Apr 17, 2013 at 09:19 PM 0
Share

The new error is :

BCE0043: Unexpected token: ).

but i don't see the error in the script that you have posted

avatar image Dracorat · Apr 17, 2013 at 09:23 PM 0
Share

You have the wrong number of ) compared to (. Double check your line.

This is a very basic compiler error, btw.

As Dr. Cox would say, You should try to figure some of this stuff out on your own, newbie, or you're never going to make it as a coder.

Show more comments
avatar image
0

Answer by netkingZ · Apr 17, 2013 at 10:18 PM

Ok I found a way to save the texture, but the saves in this way:

*http://i46.tinypic.com/2u5vsrs.png*

instead of the original image is thus:

*http://www.gamerscritic.it/wp-content/uploads/2013/01/remember-me-shot.jpg*

why?

Comment
Add comment · Show 4 · 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 Dracorat · Apr 17, 2013 at 10:33 PM 0
Share

First try with an ARGB32 image - as that's the standard for PNG format. Does that work?

I created one for you so you can be sure you have the right format:

http://dracorat.com/img/testargb.png

avatar image netkingZ · Apr 18, 2013 at 09:22 AM 0
Share

Perfect, Thanks for your help. ;)

avatar image netkingZ · Apr 18, 2013 at 09:31 AM 1
Share

This is the solution I found:

   // Opens a file selection dialog for a PNG file and saves a selected texture to the file.
         import System.IO;
   
        function Attive() {
      
           var texture =  new Texture2D (128, 128, TextureFormat.ARGB32, false);
      
            var textures =  new Texture2D (128, 128, TextureFormat.ARGB32, false);
             if (textures.Length == 0) {
                 EditorUtility.DisplayDialog("Select Textures",
                                 "The selection must contain at least one texture!", "Ok");
                 return;
             }
             var path = EditorUtility.SaveFolderPanel("Save textures to directory", "", "");
             if (path.Length != 0) {
                // for( var texture : Texture2D in textures) {
                     // Convert the texture to a format compatible with EncodeToPNG
                     if (texture.format != TextureFormat.DXT1 && texture.format != TextureFormat.RGB24) {
                         var newTexture = Texture2D(texture.width, texture.height);
                         newTexture.SetPixels(texture.GetPixels(0),0);
                         texture = newTexture;
                     }
                     var pngData = texture.EncodeToPNG();
                     if (pngData != null )
                         File.WriteAllBytes(path + "/" + nameTexture.text + ".png", pngData);
                     else
                         Debug.Log("Could not convert " + texture.name + " to png. Skipping saving texture");
                 }
                        
                     AssetDatabase.Refresh();   
     
        }
     
avatar image DeveshPandey · Jan 13, 2018 at 12:21 PM 0
Share

Here is cross platform solution to save screenshot 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.

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

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make an Array of Arrays of Textures 1 Answer

Create .png file from script, then import as asset 1 Answer

How to save runtime generated texture in Webplayer to hard drive? 1 Answer

Terrain textures "reset" 0 Answers

How to create a circle around a selected game object? 1 Answer


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