Make text2D readable at runtime / script Unity3D

I have a plugin that allows me to access images from gallery of Android phones. This gives me a texture of type Texture2D. Then I want to edit it using the GetPixels function, but it is not readable by default. How do I make the texture readable so I can use GetPixels?

Basically I allow the user to select an image from the phone and then crop it. In the following pic example, the image will be cropped with a red rectangle. It works if I make a texture beforehand. http://puu.sh/mxR3h/dfa81719b2.jpg

+2


source to share


1 answer


If you have files in your project, you can select a texture in the inspector, set the texture type to Advanced, and then set Read / Write Enabled to true.

If not, you can try using GetRawTextureData () on your existing texture, then create a new texture with the same width and height and call LoadImage () on the new texture with the data from the old one, sure markNonReadable is false. You can then do what you want on the new texture and display that while the user is cropping the image.



http://docs.unity3d.com/ScriptReference/Texture2D.GetRawTextureData.html

+2


source







All Articles