Skip to content

Instantly share code, notes, and snippets.

@aki017
Created May 25, 2017 12:08
Show Gist options
  • Save aki017/5e37db37153594bbceca4186b6f00b50 to your computer and use it in GitHub Desktop.
Save aki017/5e37db37153594bbceca4186b6f00b50 to your computer and use it in GitHub Desktop.
screenshot
var camWidth = Screen.width;
var camHeight = Screen.height;
var rt = new RenderTexture(camWidth, camHeight, 24);
Camera.main.targetTexture = rt;
var snapShot = new Texture2D(camWidth, camHeight, TextureFormat.RGB24, false);
Camera.main.Render();
RenderTexture.active = rt;
snapShot.ReadPixels(new Rect(0, 0, camWidth, camHeight), 0, 0);
Camera.main.targetTexture = null;
RenderTexture.active = null;
Object.Destroy(rt);
var bytes = snapShot.EncodeToPNG();
var form = new List<IMultipartFormSection> {new MultipartFormDataSection("image", bytes)};
var www = UnityWebRequest.Post("https://api.imgur.com/3/image", form);
www.SetRequestHeader("authorization", "Client-ID c1e604cb4c2b81f");
yield return www.Send();
Debug.Log(www.downloadHandler.text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment