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
0
Question by Whippets · Apr 02, 2013 at 11:32 PM · cameratexture2drendertexture

How to render a camera image to png

Hi, I'm trying (unsuccessfully so far) to take a camera image and get a RenderTexture from it. Once I have the RenderTexture, I need to use Texture2D.ReadPixels to read the RenderTexture, so that it can be saved out as a PNG file.

I have this code to get the initial RT from the camera...

RenderTexture c1render = new RenderTexture(80, 80, 24);

c1.targetTexture = c1render;

c1.Render();

c1.targetTexture = null;

and the following to save a Texture2D...

File.WriteAllBytes("mypath/somefile.png", texture2d.EncodeToPNG());

The bit I'm having trouble with is getting a Texture2D from the RenderTexture of my camera.

Any help would be gratefully received

Comment
Add comment · Show 2
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 Benproductions1 · Apr 02, 2013 at 11:48 PM 0
Share

Please format your code. If you don't know how visit the FAQ and watch the Video

avatar image Whippets · Apr 03, 2013 at 10:10 AM 0
Share

$$anonymous$$y apologies, I used the < code > tag, which apparently isn't the right way.

1 Reply

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

Answer by Benproductions1 · Apr 02, 2013 at 11:51 PM

Hi! there,

You can cast textures like this:

 //The variables
 var image:Texture;
 var image2d:Texture2D;
 
 //Convert the texture to a Texture2D
 image2d = image as Texture2D;

Hope this helps, Benproductions1

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 Whippets · Apr 07, 2013 at 12:05 PM 0
Share

Thanks :) It was actually more complex than that. I added RenderTextures to each camera, then used ReadPixels to get the RTs into Texture2Ds and save them to PNG files. $$anonymous$$y client then uploads the PNGs to the masterserver - so they are available for use by other clients, in the forums, etc. Took me a day to figure this all out, but it's good now.

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

11 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

Related Questions

Rendertexture to texture2d in Unity5 0 Answers

Save image from camera with post processing. 0 Answers

Why is ReadPixels on my RenderTexture creating a pure gray texture? 1 Answer

How to save a RenderTexture to a png from a different camera? 1 Answer

Why is my RenderTexture coming out distorted? 0 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