This code i found on Facebook developers. It works fine with small screen, but it crashes with screen 2000x2000. I found that occurs because of encode to png takes a lot of memory. I use another way by capturing screen first, loading image by using www, and upload on Facebook. The problem is www needs to use binary image to upload.
- Can i upload to Facebook without encode to png (because i load from local file)?
Does Facebook API has another way to upload image?
yield return new WaitForEndOfFrame(); var width = Screen.width; var height = Screen.height; var tex = new Texture2D(width, height, TextureFormat.RGB24, false); // Read screen contents into the texture tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); byte[] screenshot = tex.EncodeToPNG(); var wwwForm = new WWWForm(); wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png"); FB.API("me/photos", Facebook.HttpMethod.POST, Callback, wwwForm);