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 /
  • Help Room /
avatar image
0
Question by Dineria · Aug 25, 2016 at 10:16 AM · androidvrvideoscreenshot

Making VR-screenshot on Android

Hi there!

I was taking over a project using EasyMovieTexture to watch 360° videos on Android / GearVR. Being still new to Unity and C# my task is now to specify an area and to take a screenshot of the actual view.

The first problem is that the screenshot is always being taken from the starting view (e.g. the front although looking to the right)...

The second problem is that the screenshot seems to be taken from a time in the video about 2-3 seconds ago - althought the video is paused for the time of the process. (The idea is to specify the size of the screenshot, but that's for later.)

My actual code looks like this:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using VRStandardAssets.Utils;
 using System;
 using System.IO;
 
 [RequireComponent(typeof(VRInteractiveItem))]
 
 public class DemoController : MonoBehaviour
 {
     public MediaPlayerCtrl MediaPlayer;
     public VRInteractiveItem StartButton;
     public Camera cam;
     public Texture2D snapshot;
 
     public bool ready = false; //ready for taking screenshots
     public bool shot = false; // took screenshot
 
     void Start()
     {
         this.StartButton.OnClick += this.StartButtonClicked;
     }
         
     void StartButtonClicked()
     {
         this.StartButton.gameObject.SetActive (false);
         this.MediaPlayer.Play ();
         ready = true;
     }
 
     public IEnumerator TakeScreenshot()
     {
         yield return new WaitForEndOfFrame();
 
         GameObject go = new GameObject ();
         go.AddComponent (typeof(Camera));
         cam = go.GetComponent<Camera> ();
 
         int resolution = (int)(Screen.width);
         RenderTexture rt = new RenderTexture (resolution, resolution, 24);
         cam.targetTexture = rt;
         Texture2D screenshot = new Texture2D (resolution, resolution, TextureFormat.RGB24, false);
         cam.Render ();
         RenderTexture.active = rt;
         screenshot.ReadPixels (new Rect (0, 0, resolution, resolution), 0, 0);
         cam.targetTexture = null;
         RenderTexture.active = null;
         Destroy (rt);
         Destroy (go);
 
         byte[] bytes = screenshot.EncodeToJPG ();
         File.WriteAllBytes ("/sdcard/DCIM/Camera/SavedScreen.jpg", bytes);
     }
 
 
     void Update()
     {
         if (ready)
         {
             //taking screenshot
             if (!shot && Input.GetMouseButton(0))
             {
                 this.MediaPlayer.Pause();
                 shot = true;
             }
                 
             if (shot && Input.GetMouseButtonUp(0))
             {
                 StartCoroutine (TakeScreenshot());
                 shot = false;
                 this.MediaPlayer.Play();
             }
         }
     }
 }

I found the screenshot-method by googling as other methods result in black pictures which seems to be a common problem... Many people asks that question, but I've done everything they were told to do...

My scene is set up like this: alt text

Hope someone may help me! Thanks! :-)

settings.jpg (61.5 kB)
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

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

114 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

Related Questions

Playing a VR video on Android - Google Cardboard 0 Answers

Video Player Memory Usage 1 Answer

Playing a VR video on Android - Google Cardboard 0 Answers

Build error with VR app for google cardboard 1 Answer

App Runs fine after "Build and Run" but freezes when installed from APK 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