Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Nick_lzn · Feb 15, 2014 at 01:53 AM · create a texture

How to get the pixels of a texture which is in memory

I make some texture into AssetBundle, and loaded it in memory. I want to patch all texture in assetBundle into one atlas. But can't get the pixels of each texture.

code like this:

 assetBundleTexture.GetPixels32();

got error:

 Texture 001 is not readable, the texture memory can not be accessed from scripts.
 You can make the texture readable in the Texture Import Settings.

whether the Unity locked the memory block where the assetBundle used or not. and what should i do.

Thanks in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by erick_weil · Feb 15, 2014 at 02:12 AM

you need to set the texture as readable before GetPixels or SetPixels; see the unity script reference ( i use one simple google search ) https://docs.unity3d.com/Documentation/ScriptReference/TextureImporter-isReadable.html

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nick_lzn · Feb 15, 2014 at 02:21 AM 0
Share

sorry, i forgot mension. I had already set the source Texture file type to advance and set read/write enable on before. But it's still has this error.

avatar image erick_weil · Feb 15, 2014 at 11:43 AM 0
Share

try to copy the texture. like this : var newtexture : Texture2D = assetBundleTexture; newtexture.GetPixels32();

avatar image Nick_lzn · Feb 26, 2014 at 01:40 AM 0
Share

Thanks erick_weil. Finally, i achieve it via file operation. Here is another answer:

http://answers.unity3d.com/questions/639234/instantiating-texture2d-object-get-non-readable-er.html

it in the hope of Unity Team.

avatar image
5

Answer by Pieter_Unit040 · Sep 26, 2016 at 04:44 PM

There is another way to bypass the read/write restriction;

basically its the operation you perform when rescaling a texture (but in this case you don't actually rescale - see http://gamedev.stackexchange.com/questions/92285/unity3d-resize-texture-without-corruption)

Perhaps the following code can be optimized, but it works:

 Color32[] pixelBlock = null;
             try
                 {
                 pixelBlock = img.GetPixels32();
                 }
             catch (UnityException _e)
                 {
                 img.filterMode = FilterMode.Point;
                 RenderTexture rt = RenderTexture.GetTemporary(img.width, img.height);
                 rt.filterMode = FilterMode.Point;
                 RenderTexture.active = rt;
                 Graphics.Blit(img, rt);
                 Texture2D img2 = new Texture2D(img.width, img.height);
                 img2.ReadPixels(new Rect(0, 0, img.width, img.height), 0, 0);
                 img2.Apply();
                 RenderTexture.active = null;
                 img = img2;
                 pixelBlock = img.GetPixels32();
                 }


Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kblood · Feb 23, 2020 at 12:15 AM 0
Share

Very nice, I needed to do this with a mod for a Unity game and this helped being able to write the texture to disk. It makes a fully readable texture even, so it can also export to png, jpg and so on.

avatar image
0

Answer by Nick_lzn · Feb 26, 2014 at 01:42 AM

Thanks very much erick_weil. Finally, i achieve it via file operation. Here is another answer:

http://answers.unity3d.com/questions/639234/instantiating-texture2d-object-get-non-readable-er.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to reduce memory usage? 1 Answer

Texture3D stays black no matter what? 1 Answer

What is the best way to create a simple colored plane object in NGUI? 1 Answer

Fatal Error - Could not allocate memory 2 Answers

Hexagonal Grids 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges