Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 VRaptorTheFlash · Aug 04, 2016 at 10:15 AM · canvasvuforiaaugmented-realityaugmented reality

Is there any way to hide certain elements of UI while taking screenshot

I'm developing an Augmented Reality app. which has feature of taking photo. From one tutorial on youtube I found a way to take photo of everything displayed on screen except UI. But the problem is when I take screenshot all elements hide. This below code is same from Youtuber Edgeras Art.

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class SnapshotShare : MonoBehaviour
 {
     private AndroidUltimatePluginController androidUltimatePluginController;
     Camera mainCamera;
     RenderTexture renderTex;
     Texture2D screenshot;
     Texture2D LoadScreenshot;
     int width = Screen.width;   // for Taking Picture
     int height = Screen.height; // for Taking Picture
     string fileName;
     string screenShotName = "PictureShare.png";
 
     void Start ()
     {
         androidUltimatePluginController = AndroidUltimatePluginController.GetInstance ();
     }
 
     public void Snapshot ()
     {
         StartCoroutine (CaptureScreen ());
     }
     
     public IEnumerator CaptureScreen ()
     {
         yield return null; // Wait till the last possible moment before screen rendering to hide the UI
 
         GameObject.Find ("Canvas").GetComponent<Canvas> ().enabled = false;
         yield return new WaitForEndOfFrame (); // Wait for screen rendering to complete
         if (Screen.orientation == ScreenOrientation.Portrait || Screen.orientation == ScreenOrientation.PortraitUpsideDown) {
             mainCamera = Camera.main.GetComponent<Camera> (); // for Taking Picture
             renderTex = new RenderTexture (width, height, 24);
             mainCamera.targetTexture = renderTex;
             RenderTexture.active = renderTex;
             mainCamera.Render ();
             screenshot = new Texture2D (width, height, TextureFormat.RGB24, false);
             screenshot.ReadPixels (new Rect (0, 0, width, height), 0, 0);
             screenshot.Apply (); //false
             RenderTexture.active = null;
             mainCamera.targetTexture = null;
         }
         if (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight) {
             mainCamera = Camera.main.GetComponent<Camera> (); // for Taking Picture
             renderTex = new RenderTexture (height, width, 24);
             mainCamera.targetTexture = renderTex;
             RenderTexture.active = renderTex;
             mainCamera.Render ();
             screenshot = new Texture2D (height, width, TextureFormat.RGB24, false);
             screenshot.ReadPixels (new Rect (0, 0, height, width), 0, 0);
             screenshot.Apply (); //false
             RenderTexture.active = null;
             mainCamera.targetTexture = null;
         }
         // on Win7 - C:/Users/Username/AppData/LocalLow/CompanyName/GameName
         // on Android - /Data/Data/com.companyname.gamename/Files
         File.WriteAllBytes (Application.persistentDataPath + "/" + screenShotName, screenshot.EncodeToPNG ());  
 
         // on Win7 - it's in project files (Asset folder)
         //File.WriteAllBytes (Application.dataPath + "/" + screenShotName, screenshot.EncodeToPNG ());  
         //File.WriteAllBytes ("picture1.png", screenshot.EncodeToPNG ());
         //File.WriteAllBytes (Application.dataPath + "/../../picture3.png", screenshot.EncodeToPNG ());
         //Application.CaptureScreenshot ("picture2.png");
         GameObject.Find ("Canvas").GetComponent<Canvas> ().enabled = true; // Show UI after we're done
     }
 
     public void ShareImage ()
     {
         string path = Application.persistentDataPath + "/" + screenShotName;
         androidUltimatePluginController.ShareImage ("subject", "subjectContent", path);
     }
 
     /*public void LoadImage ()
     {
         string path = Application.persistentDataPath + "/" + screenShotName;
         byte[] bytes;
         bytes = System.IO.File.ReadAllBytes(path);
         LoadScreenshot = new Texture2D(1,1);
         LoadScreenshot.LoadImage(bytes);
         GameObject.FindGameObjectWithTag ("Picture").GetComponent<Renderer> ().material.mainTexture = screenshot;
     }
 */
     public void close ()
     {
         Application.Quit ();
     }
 }
 

The code works fine but I want the image marked with red color should be shown while buttons with blue lines should be hiddent while taking screenshot. Is it possible? To do so what should I do?

Thanks for help in advance... :)

alt text

scrproblem.jpg (107.7 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mrpmorris · Aug 04, 2016 at 10:19 AM

You have a game object called Canvas. Put all elements you want to hide as children of that. For objects you don't want to hide have a 2nd Canvas with a different name and the code won't hide that.

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 VRaptorTheFlash · Aug 06, 2016 at 03:25 PM 0
Share

I tried your solutions also bunch of other solution. But it is not capturing the image what I want. It is hiding all the Canvas from the UI

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

Cloud recognition in Vuforia 0 Answers

Is Unity 3D suitable for a furniture augmentation app? 1 Answer

Is there a way to have Vuforia and ARCore in the same app? 4 Answers

VuforiaBehavior Unable to set values properly via script 0 Answers

How can I have vuforia text recognition read in a phrase instead of just a single word. 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