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 /
This question was closed Feb 02, 2019 at 11:31 AM by Captain_Pineapple for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Captain_Pineapple · Jan 30, 2019 at 05:24 PM · spritecreateconversion2dtexture

Create Sprite from 2DTexture - only returns white-ish field

Hello there,

i aim to render a cameras view, output it as a 2dTexture and to then convert it to a sprite so that i can display it as an image in my ui.

It works if i take the step to save the image and reload it from there as sprite but this is stupid concerning performance. So the approch i wanted to take is to use Sprite.Create() to directly convert the 2DTexture into a sprite. But this only returns a evenly colored white/grey -ish field.

         RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
         myCamera.enabled = true;
         myCamera.targetTexture = rt;
         Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
         
         myCamera.Render();
         RenderTexture.active = rt;
         screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
         Sprite.Create(screenShot, new Rect(0, 0, resWidth, resHeight), new Vector2(0.5f,0.5f),100.0f);

The Texture2D screenShot contains the right content since the conversion and saving in png format works.

If anyone happens to ahve some insight for me on this i'd be glad to hear it. If you need more information on the project/code feel free to ask. Thanks in advance!

Comment
Add comment · Show 1
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 alyan8493 · Mar 30 at 08:19 AM 0
Share

What a great post that I had been seeking to Create Sprite from 2DTexture for a long time, and at last I found the some real information about it, thanks for sharing this type of information and letting us know about it. https://daswortwurdefleisch.de/

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by KISP · Jan 30, 2019 at 09:47 PM

You need to make a call to screenshot.Apply() after using ReadPixels().

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 KISP · Jan 30, 2019 at 09:51 PM 0
Share

This question might also help you: https://answers.unity.com/questions/733240/how-to-take-a-screenshot-and-apply-it-as-a-texture.html

avatar image Captain_Pineapple · Jan 31, 2019 at 08:09 AM 0
Share

Hey there, thanks a lot for the input! Gonna check this when i get home this evening :)

avatar image vietanhgba · Mar 30 at 08:56 AM 0
Share

OMG you've really saved my life, i know this is an old post but i must login and show my gratitude to you, wish you the best of luck

Follow this Question

Answers Answers and Comments

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

Sprite.Create on iOS crops images 1 Answer

Help filling in a 2dTexture. 0 Answers

how to create a sprite dynamically without provide a uv_position in code,for the reason that i have already made this in the sprite_editor. 0 Answers

How to create sprite at run time? 1 Answer

Create colored rectangle at runtime 1 Answer


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