Read Pixels or similar supported?

Hi,

In my app I want to take a screenshot in code and upload it to a web server. I know there is code to do this with ReadPixels and EncodeToPNG. AFAIK ReadPixels is not supported.

Whats the easiest way to take a screenshot in code and upload it to the web server? Id like to do this in Unity but it seems like some obj-c is needed.

Thanks in advance.

  • Matt

Hey Curve,

If that’s the case you should enable pixel reading programmatically.
I know for a fact it can be done, I just don’t have the Unity iPhone docs at hand right now.

Look into the TextureImporter Class. There should be a boolean called … ermm isReadable or something along those lines.
You’ll have to turn it to true.

I can’t seem to find it on the Unity online docs…

I’ll edit the post as soon as I can reach my mac… give me a few minutes.

EDIT:
TextureImporter.isReadable = true; // this is what you’re looking for.

Use it as such (unityscript):

var texImporter : TextureImporter = TextureImporter.GetAtPath(EditorUtility.GetAssetPath(img));
texImporter.isReadable = true;

where “img” is of Texture2D type.

Thanks, I am a bit confused tho, can I use editor scripts on the iPhone version of Unity? It doesn’t let me attach them as components, how is this script run. Ideally I would like to call my UploadPNG() method from a button press.

Editor Scripts are for the editor only, independent of the unity used.

you can’t read pixels if you talk about pixels on screen and you wouldn’t want to even if you could as the performance would drop to nowhere.
you can only read pixels from textures.

3D accelerated environments + per pixel access for usage on CPU are two things that don’t like each other very much.

In 99.9999% of the cases its not required to get the actual pixel, there are far smarter ways to achieve region clicks for example and alike.

If you really need it then you basically only have 1 option: write your own technology and an own renderer that does not use 3D but renders all into a single texture which you can use for grabbing (or better stores the data in texture and an array). PayBack has such a full cpu driven rendering.