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 Catlard · Oct 12, 2011 at 12:22 PM · screenshot

Screenshots to textures filename syntax?

There's something wrong with the way I'm finding the filepath for the texture that I'm saving in this script--does anybody know what it is?

(WORKING SCRIPT BELOW IN ANSWER!)

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 Catlard · Oct 12, 2011 at 01:01 PM 0
Share

Ok, still no luck with this. I think the filename is somehow being duplicated somewhere in this script--so it thinks the filename string is actually twice as long as it should be...

avatar image Graham-Dunnett ♦♦ · Oct 13, 2011 at 11:39 AM 0
Share

Um, don't think you want the file:\\ when passed to Application.CaptureScreenshot().

avatar image Catlard · Oct 15, 2011 at 02:07 AM 0
Share

Ah, thanks, Graham. That was part of it. I've fixed it!

Cheers

7 Replies

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

Answer by Catlard · Oct 15, 2011 at 02:08 AM

Working script:

 var filePath;
 var imageName = "pictureOfBradPitt";
 
 function Start()
 {
     filePath = "file:///" + Application.dataPath + "/" + imageName + ".png";
     print(filePath);
 }
 
 // Take a shot immediately
 function Update () 
 {
     if(Input.GetKeyDown(KeyCode.P))
     {
         Application.CaptureScreenshot(Application.dataPath + "/" + imageName + ".png");
         turnScreenShotIntoTexture();
     }
 }
 
 function turnScreenShotIntoTexture() 
 {
     yield WaitForEndOfFrame;
     var www : WWW = new WWW (filePath);
     yield www;
     myTexture = 
     renderer.material.mainTexture = www.texture; 
 }
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 wenhua · Jan 04, 2012 at 01:47 AM 0
Share

Hi sgbraunstein,i am currently doing somethings similar to your script,but i am new and no idea how to do it can you help me

I wanted to do a script that When i press $$anonymous$$ey(P).it will cature the screenshot and i wanted the saved screenshot to be display as a smaller view beside my screen, can you help me or $$anonymous$$ch me Thx

avatar image
1

Answer by Catlard · Jan 04, 2012 at 05:59 AM

Hey there!

No problem. It is a bit hard to figure out. For iOS and web browser, you can't use Application.CaptureScreenshot--you'll need to use the GetPixels function. But if you're just building a game for the desktop, Application.CaptureScreenshot will work fine. Also, It sounds like you just want to use a screenshot as a Texture2D, which you can do either on the GUI or on a plane in front of the camera. Which one you want to do is up to you--but for iOS or for some picture that's going to be changing every frame, I wouldn't use the GUI. But basically, if you want it to save the image to a "secure" location on a computer, you can use this script--although this script will erase over the old screenshot every time. If you want to save multiple screenshots, you'll have to write code that generates a new filename every time you push "P".

Here's a function that does what you want, I think:

 function turnScreenshotsIntoTexture(imageName : String) : Texture2D
 {
     var tex : Texture2D;
     var fileName = "/" + imageName + ".png";
     filePath = "file:///" + Application.persistentDataPath + fileName;
     var www : WWW = new WWW (filePath);
     yield www;
     return www.texture;
  }

}

Here's another script, that uses the "ReadPixels" method and allows for multiple images. I've messed with it a bit for you, but it should work alright:

 private var imageName = "characterImage";
 private var imageCount = 0;
 
 function Update()
 {
     if(Input.GetKeyDown(KeyCode.P))
     {
         renderer.enabled = true;
         // YOU CAN CALL takeScreenShot() HERE AND IT WILL RETURN THE TEXTURE2D TO WHATEVER YOU WANT
     }
 }
 function takeScreenShot() : Texture2D
 {
     var tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
     var myRect = Rect(0, 0, Screen.width, Screen.height);
     
     tex.ReadPixels (myRect, 0, 0, false);
     tex.Apply(false, false);    
     if(!Application.isWebPlayer)
     {
         var fileName = "/" + imageName + imageCount.ToString() + ".png";
         Application.CaptureScreenshot(Application.persistentDataPath + fileName);
         filePath = "file:///" + Application.persistentDataPath + fileName;
     }
     imageCount++;
     return tex;
 
 }
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 wenhua · Jan 04, 2012 at 06:52 AM 0
Share

Thx alot anyway

avatar image wenhua · Jan 04, 2012 at 07:04 AM 0
Share

// YOU CAN CALL takeScreenShot() HERE AND IT WILL RETURN THE TEXTURE2D TO WHATEVER YOU WANT

I only create a GUITexture and i dunno how to CALL it

isit takeScreenShot = guiTexture.texture; ??

avatar image wenhua · Jan 04, 2012 at 07:55 AM 0
Share

O i try the script but its not functioning,have you try it up,is it just copy and paste

whats "ReadPixels" anyway and i am lost lol

avatar image
0

Answer by wenhua · Jan 04, 2012 at 01:48 AM

Hi sgbraunstein,i am currently doing somethings similar to your script,but i am new and no idea how to do it can you help me

I wanted to do a script that When i press Key(P).it will cature the screenshot and i wanted the saved screenshot to be display as a smaller view beside my screen, can you help me or teach me Thx

Comment
Add comment · 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
0

Answer by wenhua · Jan 04, 2012 at 06:49 AM

Hi sgbraunstein,i think you abit misunderstand what i saying,actually i have this script

using UnityEngine; using System.Collections;

public class TakeScreenshot : MonoBehaviour {
private int screenshotCount = 0;

 // Check for screenshot key each frame
 void Update()
 {
     // take screenshot on up->down transition of F9 key
     if (Input.GetKeyDown("k"))
     {        
         string screenshotFilename;
         do
         {
             screenshotCount++;
             screenshotFilename = "screenshot" + screenshotCount + ".png";

         } while (System.IO.File.Exists(screenshotFilename));
         
         Application.CaptureScreenshot(screenshotFilename);
     }
 }

}

This script works the same as cature a screenshot and save it in the file by pressing k

what i mean is i wanted to add in another effects and thats is when i cature the screenshot,i not only want to save this screenshot but in the same time also display the screenshot on the scene at a smaller view>>just like when we press on camera a smaller view pop beside<<

So i create a GUITexture and put the Texture to None(Texture), so i wanted it to be like this

When i press k,it will screenshot and put this screenshot into the GUITexture

Comment
Add comment · 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
0

Answer by wenhua · Jan 05, 2012 at 03:41 AM

Hi sgbraunstein,pls help me why your script is not working??its not caturing any view or what??

Comment
Add comment · 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
  • 1
  • 2
  • ›

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

Is is possible to output screenshots from Unity? 5 Answers

Specifying a camera using ScreenShotMovie and changing capture rate while not affecting playback rate 1 Answer

Problem with saving screenshot 0 Answers

Screenshot in Webplayer with Antialiasing 0 Answers

How to get a screenshot in game and re-use in game? 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