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 flamy · May 26, 2013 at 08:07 AM · camerarendertexturescreenshotpng

Wierd Screen Shot Problem, texture of screen shot looks different in editor and in system.

Hello, I have run into a very strange problem. I am taking screenshot of certain area of the screen using the following code.

IEnumerator Save() { camera.enabled = true; //camera.targetTexture = new RenderTexture(512,512,24,RenderTextureFormat.ARGB32,RenderTextureReadWrite.sRGB);

     originalSide = Manager._instance.side;
     
     Manager._instance.side = 1;
     _shirtHandler.LoadPattern();
     
     //camera.Render();
     //yield return new WaitForEndOfFrame();
     RenderTexture.active = camera.targetTexture;
     Texture2D texFront = new Texture2D(camera.targetTexture.width,camera.targetTexture.height,TextureFormat.ARGB32,false );
     texFront.ReadPixels(new Rect(0,0,512,512), 0, 0);
     texFront.Apply();
     
     yield return null;
     Manager._instance.side = 1;
     _shirtHandler.LoadPattern();
     
     //camera.Render();
     //yield return new WaitForEndOfFrame();
     RenderTexture.active = camera.targetTexture;
     Texture2D texBack = new Texture2D(camera.targetTexture.width,camera.targetTexture.height,TextureFormat.ARGB32,false );

     texBack.ReadPixels(new Rect(0,0,512,512), 0, 0);
     texBack.Apply();
     Manager._instance.isSaving = false;
     
     //temp.material.mainTexture = texFront;
     camera.enabled=false;
     yield return null;
     //upload it to server..
     byte[] bytesFront= texFront.EncodeToPNG();
     File.WriteAllBytes("C:/Users/Vijay/Desktop/Front.png", bytesFront );
     File.WriteAllBytes("C:/Users/Vijay/Desktop/Back.png", texBack.EncodeToPNG());
     
     Manager._instance.side = originalSide;
     _shirtHandler.LoadPattern();
 }


There are two cameras in game. one is the main camera and another one is only for the purpose of saving the screen shot of certain area of screen. I am enabling the camera at the time of capturing alone. I am getting the screenshot as per my requirement but only until i save it to local... when I apply the captured screenshot to a material in game it is working fine but whn i save the screen shot, I could hardly see the colors in there. and when i import the saved screen shot into unity, it is looking normal. But every where else except unity im seeing an image without much colors...I am attaching both the versions in this mail...

The saved screenshot

alt text

The above might look like empty image but has colors in it, whn zoomed a bit.

The same file after importing to unity,

alt text

Could someone tell me why this is happening??

front.png (75.2 kB)
untitled.png (44.0 kB)
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 flamy · May 26, 2013 at 03:21 PM 0
Share

anyone??...

1 Reply

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

Answer by robertbu · May 26, 2013 at 05:37 PM

Your alpha values in the texture are very small. Most of the shaders in unity ignore the alpha channel of the texture, so in the preview or when using this texture on a material that does not use the alpha channel, the image will look fine. To see your image with the alpha channel, create a material using your texture and the Unlit/Transparent shader. Place this material on a game object. You will see your image as a ghost.

Comment
Add comment · Show 4 · 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 flamy · May 27, 2013 at 05:40 AM 0
Share

hi robert, You are right. the alpha in the texture is very low... but how do i solve this... I checked the materials of the objects that are getting screen shoted, they all have 255 alpha.. what else the problem could be. FYI: the camera that takes the screenshot is a secondary camera.

avatar image robertbu · May 27, 2013 at 06:03 AM 0
Share

I don't know what is causing this issue. You code looks fine (though I've only had a limited amount of exposure to RenderTextures). Did you turn off the main camera while you take the shot? A hackish solution would be to GetPixels32() and set all the alphas to 255 before calling EncodeToPng().

avatar image flamy · May 27, 2013 at 06:47 AM 0
Share

ya I thought of doing that but i have to save like 8 images in a row.. which is causing a struck up in program for like 15-20 secs (even in my high end machine), when get pixes and apply is used..

And I am not turning off the main cam. will it affect in anyway!!... the problem is I cant coz of other scripts

avatar image flamy · May 27, 2013 at 07:53 AM 1
Share

thanks robert, I have solved it...

While creating the texture, I have created RGB24 ins$$anonymous$$d of ARGB32.. which solves the issue.

Texture2D texBack = new Texture2D(camera.targetTexture.width,camera.targetTexture.height,TextureFormat.RGB24,false );

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

13 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

Related Questions

Rendering screenshot using multiple cameras and one rendertexture 0 Answers

Taking huge screenshots using camera array? 3 Answers

Taking screenshot from a second camera 0 Answers

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

Save rendertexture to image in file 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