Question by
gunqwn · Sep 22, 2017 at 06:25 AM ·
screenshotreadpixels
Unity3d Texture2D.ReadPixels problem when convert to sprite.
Hi, I am develop a game with capture screen feature. so i use Texture2D.ReadPixels and convert it to spite so that i can assign my screenshoot to Unity UI.
this is my code
public GameObject UiDisplay;
void OnPostRender() {
Texture2D tex = new Texture2D(Screen.width, Screen.height);
tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
tex.Apply();
UiDisplay.SetActive(true);
UiDisplay.GetComponent<Image> ().sprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);;
grab = false;
}
everything work fine, but when i capture screen and there is object with transparent texture like tree. the result is like picture bellow.
capture.jpg
(47.3 kB)
Comment
Your answer
Follow this Question
Related Questions
How to ReadPixels from square area right in the middle of the screen? 1 Answer
ReadPixels - Screen.Width/Height in not maximized editor mode give unreliable results 0 Answers
ReadPixels returns empty texture 0 Answers
Texture2D.ReadPixels doesn't capture image effects. 1 Answer
camera.ReadPixels creating ugly textures 0 Answers