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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by el-santia93 · Dec 03, 2013 at 09:07 AM · androidtexture

save the screenshot taken in game into android device's memory

Please I need help with this i have been able to take a screenshot i just need to save it into a folder of the android device(gallery documents..anyone).I have researched this but can't seem to find a working solution.Would really appreciate any help i can get with this. My current code is pasted below

 import System.IO;
 var explosion:GameObject[];
 var dec:GUITexture;
 var levelToLoad:String;
 // increment our filename
 private var count:int = 0;
 
 /**
 * Test key
 */
 function Update()
 {
     
 }
 
 
 
  //Take the screen buffer and spit out a JPG
 
 function ScreenshotEncode()
 {
     // wait for graphics to render
     yield WaitForEndOfFrame();
     
     // create a texture to pass to encoding
     var texture:Texture2D = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
     
     // put buffer into texture
     texture.ReadPixels(Rect(0.0, 0.0, Screen.width, Screen.height), 0.0, 0.0);
     texture.Apply();
 
     // split the process up--ReadPixels() and the GetPixels() call inside of the encoder are both pretty heavy
     yield;
     
     // create our encoder for this texture
     var encoder:JPGEncoder = new JPGEncoder(texture, 75.0);
     
     // encoder is threaded; wait for it to finish
     while(!encoder.isDone)
         yield;
     
     // save our test image (could also upload to WWW)
     File.WriteAllBytes(Application.persistentDataPath + "/../MyTree-" + count + ".jpg", encoder.GetBytes());
     yield WaitForSeconds(1);
     //play sound here
     //System.Diagnostics.Process.Start("mspaint.exe","MyTree-" + count + ".jpg");
     count++;
 guiTexture.enabled=true;
 dec.guiTexture.enabled=true;;
 Application.LoadLevel(levelToLoad);    
 }
 function OnMouseDown(){
 Destroy(GameObject.FindWithTag("chickens"));
 Destroy(GameObject.FindWithTag("pal"));
 guiTexture.enabled=false;
 dec.guiTexture.enabled=false;
 Instantiate(explosion[Random.Range(0,explosion.Length)]);;
 yield WaitForSeconds(2);
 ScreenshotEncode();
         }
 
    
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 flamy · Dec 03, 2013 at 10:09 AM 0
Share

do you want only jpg? png is easy to make in unity3d

avatar image el-santia93 · Dec 03, 2013 at 10:13 AM 0
Share

either will do so long i can save into a folder on the device

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

You can use this plugin For screenshots http://u3d.as/86U If you want to download and save - http://u3d.as/9Ee

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by flamy · Dec 03, 2013 at 11:39 AM

See the example from this link, This exactly does what you want.

It captures screen shot and saves in a location.

http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.EncodeToPNG.html

Instead of uploading link the above link save the file to datapath or persistent datapath.

 // For testing purposes, also write to a file in the project folder
 // File.WriteAllBytes(Application.dataPath + "/../SavedScreen.png", bytes);

these lines would be commented in the example, replace with your required path strings.

Comment
Add comment · Show 3 · 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 el-santia93 · Dec 03, 2013 at 02:01 PM 1
Share

Okay,after much research i have solved it using this

 Application.CaptureScreenshot( "../../../../DCI$$anonymous$$/Camera/screenshot+count+.png");

Now this is the important part For this to work on Android, Write Access needs to be set to "External (SDCard)" in the Player Settings.Player Settings->Android->Other settings

avatar image el-santia93 · Dec 03, 2013 at 02:05 PM 0
Share

I have set a count variable so that each time the player takes a screenshot the count incrases like screeshot1,screenshot2 etc but now the output is just screenshot+count+.png..how do i resolve this?

avatar image fonko · Feb 23, 2015 at 12:17 PM 0
Share

lol... you should have set double quotes there also... Application.CaptureScreenshot( "../../../../DCI$$anonymous$$/Camera/screenshot" +count+ ".png"); right?

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

18 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 avatar image avatar image avatar image avatar image

Related Questions

Save a Texture2D for android 1 Answer

how to make high quality textures with low size of downlaod 1 Answer

Please Help!!! my LineRenderer Script is not show when bulid on android device 1 Answer

Android texture quality problem 0 Answers

GUI button doesn't appear on Android 0 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