- Home /
Question by
M_Shazaib · Dec 15, 2018 at 03:59 PM ·
scripting problemgeneral
How to make the screenshot and share button not visible in the screen shot it self
I made a screen capture and share button for an AR app but I face a problem 1. I don't want the share button itself to be visible in the screenshot plz tell me what changes are to be made to do this I attached my script below
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
using System.IO;
using System;
/*
* https://github.com/ChrisMaire/unity-native-sharing
*/
public class Test : MonoBehaviour {
public string ScreenshotName = "AR_FLAG.png";
public void ShareScreenshotWithText(string text)
{
string screenShotPath = Application.persistentDataPath + "/" + ScreenshotName;
if(File.Exists(screenShotPath)) File.Delete(screenShotPath);
ScreenCapture.CaptureScreenshot(ScreenshotName);
StartCoroutine(delayedShare(screenShotPath, text));
}
//CaptureScreenshot runs asynchronously, so you'll need to either capture the screenshot early and wait a fixed time
//for it to save, or set a unique image name and check if the file has been created yet before sharing.
IEnumerator delayedShare(string screenShotPath, string text)
{
while(!File.Exists(screenShotPath)) {
yield return new WaitForSeconds(.0f);
}
NativeShare.Share(text, screenShotPath, "", "", "image/png", true, "");
}
//---------- Helper Variables ----------//
private float width
{
get
{
return Screen.width;
}
}
private float height
{
get
{
return Screen.height;
}
}
//---------- Screenshot ----------//
public void Screenshot()
{
// Short way
StartCoroutine(GetScreenshot());
}
//---------- Get Screenshot ----------//
public IEnumerator GetScreenshot()
{
yield return new WaitForEndOfFrame();
// Get Screenshot
Texture2D screenshot;
screenshot = new Texture2D((int)width, (int)height, TextureFormat.ARGB32, false);
screenshot.ReadPixels(new Rect(0, 0, width, height), 0, 0, false);
screenshot.Apply();
// Save Screenshot
Save_Screenshot(screenshot);
}
//---------- Save Screenshot ----------//
private void Save_Screenshot(Texture2D screenshot)
{
string screenShotPath = Application.persistentDataPath + "/" + DateTime.Now.ToString("dd-MM-yyyy_HH:mm:ss") + "_" + ScreenshotName;
File.WriteAllBytes(screenShotPath, screenshot.EncodeToJPG());
// Native Share
StartCoroutine(DelayedShare_Image(screenShotPath));
}
//---------- Clear Saved Screenshots ----------//
//public void Clear_SavedScreenShots()
// {
//string path = Application.persistentDataPath;
//DirectoryInfo dir = new DirectoryInfo(path);
//FileInfo[] info = dir.GetFiles("*.png");
//foreach (FileInfo f in info)
// {
//File.Delete(f.FullName);
// }
// }
//---------- Delayed Share ----------//
private IEnumerator DelayedShare_Image(string screenShotPath)
{
while (!File.Exists(screenShotPath))
{
yield return new WaitForSeconds(.05f);
}
// Share
NativeShare_Image(screenShotPath);
}
//---------- Native Share ----------//
private void NativeShare_Image(string screenShotPath)
{
string text = "Celebrate #Bahrain National Day with #AugmentedReality #Flag Point your own #ARflag and share with your friends #BahrainNationalDay #BahrainFlag #AR #BahrainFlagAR";
string subject = "AR_FLAG";
string url = "www.munfarid.org";
string title = "Select Sharing app";
#if UNITY_ANDROID
subject = "AR_FLAG";
text = "Celebrate #Bahrain National Day with #AugmentedReality #Flag Point your own #ARflag and share with your friends #BahrainNationalDay #BahrainFlag #AR #BahrainFlagAR";
#endif
#if UNITY_IOS
subject = "Test subject.";
text = "Test text";
#endif
// Share
NativeShare.Share(text, screenShotPath, url, subject, "image/png", true, title);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612184027im_/https://answers.unity.com/themes/thub/images/avi.jpg)