- Home /
Question by
kk3hi3123 · Dec 27, 2018 at 10:09 AM ·
android buildscreenshot
Camera Screenshot on mobile full of noise
I want to take a screenshot using another camera in Unity. I have read some sample project and watched this video.
And now, I can take screenshot and save it somewhere when using Unity Editor. But when I build it into my Android devices, the images become full of noise.
The image is too large so please view the image in my post on StackOverflow.
Here is my code:
void Awake()
{
myCamera = GetComponent<Camera>(); // Camera is disable in the scene
myCamera.targetTexture = new RenderTexture(Screen.width, Screen.height, 24);
}
public void takeScreenShot(){
myCamera.enabled = true;
StartCoroutine(Capture());
}
IEnumerator Capture(){
yield return new WaitForEndOfFrame();
Texture2D result = new Texture2D(myCamera.targetTexture.width, myCamera.targetTexture.height, TextureFormat.RGB24, false);
myCamera.Render();
RenderTexture.active = myCamera.targetTexture;
Rect rect = new Rect(0, 0, myCamera.targetTexture.width, myCamera.targetTexture.height);
result.ReadPixels(rect, 0, 0);
byte[] byteArray = result.EncodeToPNG();
string filePath = Application.persistentDataPath + "/ScreenShot.png";
System.IO.File.WriteAllBytes(filePath, byteArray);
Debug.Log("ScreenShot saved to: " + filePath);
Destroy(result);
myCamera.enabled = false;
}
Comment
Your answer
Follow this Question
Related Questions
Is there any way to detect a screenshot taken in android and ios apps? 1 Answer
Sending e-mails with attachments from webplayer 1 Answer
Print a screenshot (with the user's printer) 1 Answer
Save Image to Android Photo gallery 1 Answer
Screenshot script not uploading PNG to server when used with key trigger 1 Answer