Log in or register to post comments

Black Background in screenshot

August 9, 2017 - 8:23am #1

I'm actually using the below script and its working fine. This script is actually used to share the screenshot. But my problem is after capturing the screenshot,the background
appears to be black. How to avoid this black background? Pls Help!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;

public class NativeShareScript : MonoBehaviour
{
public GameObject CanvasShareObj;

private bool isProcessing = false;
private bool isFocus = false;

public void ShareBtnPress()
{
if (!isProcessing)
{
CanvasShareObj.SetActive(true);
StartCoroutine(ShareScreenshot());
}
}

IEnumerator ShareScreenshot()
{
isProcessing = true;

yield return new WaitForEndOfFrame();

Application.CaptureScreenshot("screenshot.png", 2);
string destination = Path.Combine(Application.persistentDataPath, "screenshot.png");

yield return new WaitForSecondsRealtime(0.3f);

if (!Application.isEditor)
{
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + destination);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"),
uriObject);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"),
"Type your comments");
intentObject.Call<AndroidJavaObject>("setType", "image/jpeg");
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject chooser = intentClass.CallStatic<AndroidJavaObject>("createChooser",
intentObject, "Share your new score");
currentActivity.Call("startActivity", chooser);

yield return new WaitForSecondsRealtime(1);
}

yield return new WaitUntil(() => isFocus);
CanvasShareObj.SetActive(false);
isProcessing = false;
}

private void OnApplicationFocus(bool focus)
{
isFocus = focus;
}
}

AttachmentSize
Image icon Screenshot.jpeg26 KB

Black Background in screenshot

August 17, 2017 - 11:35am #2

Hello degeta,

This article goes over a couple different ways to get the camera image in Vuforia https://library.vuforia.com/content/vuforia-library/en/articles/Solution/Working-with-the-Camera.html#How-To-Access-the-Camera-Image-in-Unity

Thanks,

-Vuforia Support

Log in or register to post comments