Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 lixkam · Feb 16, 2019 at 04:51 PM · runtimespriterenderersprite rendererscreencapture

Call and Render a Screenshot at Runtime,How do i render a sprite that was created at runtime (Screen Cap Question)

Im trying to setup a screen Capture and display captured image on the UI, but i don't know how to display the sprite that i have captured that is stored in the asset folder.

If the screencapture that i created was is stored in my asset folder as a Texture 2D & UI (at runtime)

how do i call 'this' sprite and display it on the UI?,Im trying to setup a screen Capture and display captured image on the UI, but i don't know how to display the sprite that i have created and stored in the asset folder.

If the screencapture that i created was is stored in my asset folder as a Texture 2D & UI (at runtime)

how do i call it and render it onto my UI?

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

2 Replies

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

Answer by hollums · Feb 16, 2019 at 05:48 PM

If you already have a reference to the Texture2D from your project that was made at runtime, then all you should have to do is create a sprite from that object using Sprite.Create and apply it as the sprite for the image component you wish to place the render to.

Take a look at this script for your reference, if you want to see it running add this component to an object in your scene, add an image somewhere in your UI to display the screen capture to and link it with the outputImage field in the inspector. At runtime press the Space key to see the output written in your image component.

 namespace PlayNice.UnityHelp
 {
     public class ScreenShotHelper : MonoBehaviour 
     {
         public Image outputImage;
         bool isCapturing = false;
         Texture2D currentCapture;
 
         IEnumerator CaptureRoutine()
         {
             yield return new WaitForEndOfFrame();
             try
             {
                 isCapturing = true;
                 currentCapture = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
                 currentCapture.ReadPixels (new Rect (0, 0, Screen.width, Screen.height), 0, 0, false);
                 currentCapture.Apply ();
             } 
             catch (System.Exception e)
             {
                 Debug.LogError ("Screen capture failed!");
                 Debug.LogError (e.ToString ());
                 isCapturing = false;
             }
         }
 
         void LateUpdate()
         {
             if (Input.GetKeyDown (KeyCode.Space))
             {
                 ScreenshotToImage ();
             }
 
             if (isCapturing && currentCapture != null)
             {
                 Sprite sprite = Sprite.Create(currentCapture, new Rect(0, 0, Screen.width, Screen.height), new Vector2(0, 0));
                 if(outputImage)
                     outputImage.sprite = sprite;
                 isCapturing = false;
             }
         }
 
         public void ScreenshotToImage()
         {
             StartCoroutine (CaptureRoutine ());
         }
     }
 }
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 lixkam · Feb 16, 2019 at 10:17 PM

@hollums Oh mang!!! this works like a charm. Thank you so much, i tried so many different but this is exactly what i need to play around with my system

Thanks!!!

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 hollums · Feb 17, 2019 at 01:46 AM 0
Share

No problem! Good luck with it! If that's everything, do you $$anonymous$$d marking this as the correct solution so this question is set as resolved? Thanks!

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

101 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

Related Questions

Translucent sprites appear solid 0 Answers

Sprite not updating color. 1 Answer

Sprite on SpriteRenderer not keyframing? 1 Answer

Export objects to a .3DS file at runtime 1 Answer

Unity 2D problem with displaying sprites in final build 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