Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
0
Question by link1375 · Dec 11, 2017 at 12:29 PM · texture2dimagecolor changememory usagestretching

How to redye pixels of a texture?

I have a picture (256 x 512) which I use as a texture for a RawImage which has bigger resolution (around 500 x 900). The first question is, how do i get the Color[] of the stretched texture or just access the stretched texture? When I call RawImage.texture.getPixels() I only get an array with 256x512 entries but I need 500x900. The second question is, how to redye single Pixels? Like in the example above I want to iterate over the pixels of the stretched Texture and everytime I find a specific color I want to change the color of this pixel e.g. to red. If I do this with SetPixel() the whole texture gets the color. I also tried to instantiate a RawImage of the size of one pixel for each pixel but this leads to a very high memory usage and also took a long time which is obvious if you remember that you have to instantiate around 450.000 RawImages. As I want to adapt the script for a WebCamTexture and I didn't work out how to delete Textures from memory I chose this method since once I instaniated the textures/RawImages I could redye them the way I want. Are there better possibilities?

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

1 Reply

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

Answer by Remy_Unity · Dec 11, 2017 at 01:03 PM

First, RawImage.texture.getPixels() will always return a 256*512 array in you case because the texture is at this size. Displaying it at 500*900 (or anything else) is just the GPU rendering a quad with this texture and applying a filter to show it bigger than it is (pixel wise).
Anyway, using Texture2D.SetPixel(x, y, color) (doc : https://docs.unity3d.com/ScriptReference/Texture2D.SetPixel.html) should correctly change a single pixel in the texture. Just don't forget to call texture2d.Apply() after.
And finally, maybe using a shader to do the color replacement would be more optimal.

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

76 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 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 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 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

Continuously scanning and recognising text with Unity3D on Android 0 Answers

How do I get file size of texture? 1 Answer

Create, export, and then load a huge image. 2 Answers

how we can Enabled Texture Read/Write property run time from script for Android and IOS Devices ?? 0 Answers

Problem Image GUI 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