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 blamejane · Oct 02, 2015 at 07:02 AM · renderingpngencode

help needed trying to save render texture as png

I have two cameras.

1 - main camera which rotates around my scene and shows the GUI.

2 - small thumbnail camera in a fixed position doesn't show UI, and has it's target set to a render texture.

Camera #2 works perfectly as a picture-in-picture camera, but I can't figure out how to save the render texture to a png; using this camera's position and rotation, etc.

The code I have (below) is attached to my thumbnail (#2) camera and it will render a png, however it's not what camera #2 sees, it's whatever the main camera (#1) sees; which is a completely different point-of-view and it includes the UI.

I simply want to read the pixels of the render texture (which is assigned to thumbnail #2 camera and it looks perfect) and write them out. I don't understand what I'm doing wrong, or maybe this isn't possible.

Here's the code I've pieced together from stuff found on the web:

     public IEnumerator TakeScreenShot()
     {
         int startPosX = (Screen.width - slotTexture.width) / 2;
         int startPosY = (Screen.height - slotTexture.height) / 2;
 
         Camera camOV = OVcamera.GetComponent<Camera>();
 
         Texture2D imageOverview = new Texture2D(camOV.targetTexture.width, camOV.targetTexture.height);
 
         RenderTexture currentRT = RenderTexture.active;
         
         RenderTexture.active = camOV.targetTexture;
 
         camOV.Render();
         
         yield return new WaitForEndOfFrame();
 
         imageOverview.ReadPixels(new Rect(startPosX, startPosY, slotTexture.width, slotTexture.height), 0, 0);
         imageOverview.Apply();
 
         RenderTexture.active = currentRT;
         
         // Encode texture into PNG
         byte[] bytes = imageOverview.EncodeToPNG();
         
         path = Application.persistentDataPath + "/" + filename;
         
         System.IO.File.WriteAllBytes(path, bytes);
     }
 

Anyone have an idea how this can be done?
Seems like I should be able to have several cameras (in various locations) each with render textures assigned and then save them out.

Help!

Comment
Add comment · Show 1
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 blamejane · Oct 01, 2015 at 10:23 PM 0
Share

c'mob how long does it take to get a question posted!

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to export video? Cinemachine and Timeline question 4 Answers

Question about screenshots and facebook integration 1 Answer

Rendering translucent objects with Unity Recorder 0 Answers

Trying to use multiple png files for a single texture 0 Answers

EncodeToPng and WebCamTexture PROBLEM 4 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