Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 Jun 22 - 14 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 a1fonzo · Aug 11, 2015 at 01:31 AM · camerascreenshotcontentoff-screen

Taking a screenshot from a secondary off-screen camera?

I have been trying create a system for an iOS game that will generate a random photo that users can then share over social media via the Prime31 Social Networking plugin. I am creating the image that I would like for users to be able to share using various Gameobjects. They are all being rendered off-screen but while the game is running.

It seems like I should be able to do this very simply, however I am struggling to find a way to generate a PNG out of my off-screen content. I used the little documentation available on this topic to piece together the attached script. As far as I have seen, everyone is focused on taking screenshots of content that is in view of the main camera and therefore also to the user.

My script currently crashes Unity, I know this is caused by the invalid negative parameter for the new rectangle I am trying to create off-screen, but I wanted to illustrate what I am trying to do.

So to sum up my questions include, is it even possible to convert my off-screen content to a PNG? How would I go about generating a PNG from the content if it is possible? Is my current method the best way to capture that content and package it for use with the Prime31 plug-in?

Other notes, I don't have Unity Pro so the RenderTexture method of taking screenshots is out of question, even though I'm not sure if it could be used to solve my problem.

Attached code:

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class ScreenShot_Taker : MonoBehaviour {
     
     Camera screenshotCam;
     RenderTexture renderTex;
     int width = 200, height = 200;
 
     void Awake() {
         screenshotCam = GetComponent<Camera>();
         renderTex = new RenderTexture(width, height, 24);
         screenshotCam.targetTexture = renderTex;
     }
 
     Texture2D CaptureScreenshot () {
         RenderTexture tempRT = RenderTexture.active;
         RenderTexture.active = renderTex;
         screenshotCam.Render();
         Texture2D screenshot =  new Texture2D(width, height, TextureFormat.RGB24, false);
         screenshot.ReadPixels(new Rect(-38.85f, 5f, width, height), 0, 0);
         screenshot.Apply(false);
         RenderTexture.active = tempRT;
         return screenshot;
     }
 
     void SaveScreenshot() {
         string filePath = Application.dataPath + "/screenshot.png";
         File.WriteAllBytes(filePath, CaptureScreenshot().EncodeToPNG());
     }
 }

 
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 killer777 · Oct 22, 2016 at 08:30 PM 0
Share

i have the same problem, please help!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Take screenshot of pixels OUTSIDE the game window? 0 Answers

How to scale 3D HUD with Camera Size? 1 Answer

how to preview screenshot immediately after its taken ?? 0 Answers

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

Open screenshot in file location 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