• 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 DJJD · Sep 09, 2019 at 12:40 AM · cameraimagesavescreenshotscreencapture

Can you change ScreenShotCapture Camera?

Hey guys!

I'm making this application where you have a character that will have multiple poses and saved as jpg. For now everything works great!

The thing is, I make multiple screenshots very fast, making the different images fly on the screen while the user waits for the result, which is just ugly.

I would want to add a 2nd camera with a loading screen while the screenshots are taken behind this screen. So, 1st camera would take the screenshot while the 2nd would display a loading scren to the user.

Is that possible? Here what I have right now :

   // Check Date to Scren Capture
         string date = GetDate();
         int sceneCount = 0;
         int pageCount = 1;
         GameObject[] activeScenes = new GameObject[2];
         sceneSelectionElementsParent.SetActive(false);
 
         foreach (int sceneId in scenesToLoad)
         {
             GameObject scene = availableScenesToLoad[sceneId];
             activeScenes[sceneCount] = scene;
             scene.transform.position = sceneLocation[sceneCount].position;
             scene.SetActive(true);
             Debug.Log("Scene " + sceneId + " has been loaded!");
             sceneCount++;
 
             if((sceneCount) == 2)
             {
                 ScreenCapture.CaptureScreenshot("MyCharacter_0" + pageCount + "_" + date + ".jpeg");
                 yield return new WaitForSeconds(0.1f);
                 sceneCount = 0;
                 pageCount++;
                 activeScenes[0].SetActive(false);
                 activeScenes[1].SetActive(false);
             }
         }
Comment
Add comment
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 Reply

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

Answer by BastianUrbach · Sep 09, 2019 at 09:09 AM

I believe CaptureScreenshot can only capture what's on the screen but you can render a camera into a RenderTexture and convert the result into a JPG:

 static void CaptureCamera(Camera camera, string path, int width, int height) {
     var renderTexture = new RenderTexture(width, height, 16);
     var texture2D = new Texture2D(width, height);
 
     var target = camera.targetTexture;
     camera.targetTexture = renderTexture;
     camera.Render();
     camera.targetTexture = target;
 
     var active = RenderTexture.active;
     RenderTexture.active = renderTexture;
     texture2D.ReadPixels(new Rect(0, 0, width, height), 0, 0);
     RenderTexture.active = active;
 
     texture2D.Apply();
     System.IO.File.WriteAllBytes(path, texture2D.EncodeToJPG());
 }
Comment
Add comment · Show 2 · 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 DJJD · Sep 09, 2019 at 12:15 PM 0
Share

Very interesting! I'll be checking this out tonight when I come back from work, but it seems like a great idea!

Thanks a lot!

avatar image DJJD DJJD · Sep 12, 2019 at 10:40 PM 0
Share

Changed a bit of things here and there, but the general idea behind it is exactly what I needed.

Thanks a lot man :D

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

178 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 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 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 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 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 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 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 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 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 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

How to do screenshot and save it in phone as png(not texture)? 0 Answers

Is there any way to execute ReadPixels (for capturing a screenshot) but on a camera that is currently not displaying anything on screen? 2 Answers

capture a screen shot and show in the album folder 1 Answer

Finding the right ortho size to fill the screen with an object 1 Answer

How to get a Rect from Image or RectTranform? 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