[solved] How to save instance of the texture?

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

         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.

Help me. Thank you.

–

up , please .

–

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

–

The code in the page uses the old getters. You have to use this instead : if (GetComponent<Renderer>().IsVisibleFrom(Camera.main)) Debug.Log("Visible"); else Debug.Log("Not visible"); (A little search on Google would have given you this question )

–

2 Answers

2

You can save the texture by doing:

import System.IO;

...

File.WriteAllBytes(Application.persistentDataPath + "/" + someFilename, someTexture.EncodePNG());

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.

–

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());

–

Good point

–

The new error is : BCE0043: Unexpected token: ). but i don't see the error in the script that you have posted

–

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.

–

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?

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

–

Perfect, Thanks for your help. ;)

–

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.

–

Of course you will need the "RendererExtensions.cs" in your project. Where do you think does the "IsVisibleFrom" method comes from otherwise? It's an extension method for the Renderer class. How you access the renderer component is a different story. The .renderer shortcut property doesn't exist / works anymore so you have to use GetComponent to access the Renderer. Though this is just fundamental / basic Unity knowledge.

–