Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by dee7800 · Oct 10, 2015 at 01:18 PM · rendertexturepngreadpixelstargettexture

High Resolution ScreenShot Using targetTexture, ReadPixels and EncodeToPNG - Javascript

I am trying to get a screen shot with ReadPixels and enlarge the resolution for output. I will be taking a subsection (cropping it) before saving as a png to disk, so i can't rely on the Application.CaptureScreenshot method.

The problem i am experiencing is the enlarged output is highly distorted Some portions are squished, while others are stretched. Attached are an unscaled and scaled example to show the distortion.

any help would be appreciated.

below is my function in javascript:

 function screen_grab3(png_name:String, cam:Camera){
     yield WaitForEndOfFrame();
     //set render size and make texture
     var scale:float=4;
     var r_width:int=scale*Mathf.Floor(cam.pixelWidth);
     var r_height:int=scale*Mathf.Floor(cam.pixelHeight);
     var scaled_rt:RenderTexture=new RenderTexture(r_width, r_height, 24);
     
     //make 2d texture for writing to
     var screen_grab:Texture2D=new Texture2D(r_width, r_height, TextureFormat.RGB24, false);
     
     // set cam to render to the texture
     cam.targetTexture=scaled_rt;
     cam.Render();
     RenderTexture.active=scaled_rt;
     
     //write screenshot
     screen_grab.ReadPixels(new Rect(0, 0, r_width, r_height), 0, 0);
     screen_grab.Apply();
     
     //revert cam settings
     cam.targetTexture=null;
     RenderTexture.active=null;
     
     //convert to png
     var bytes=screen_grab.EncodeToPNG();
     
     //destroy stuff
     Destroy (screen_grab);
     //Destroy(scaled_rt);
     
     //save to file
     var path:String=Application.persistentDataPath+"/"+png_name+".png";
     File.WriteAllBytes(path, bytes);
 }

report01-strech-scale.png (89.3 kB)
report01-normal.png (51.4 kB)
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

Answer by TheFloatingSheep · Oct 11, 2015 at 06:55 PM

I was working on an app and i had 2 textures with the type set on Advanced, Format: RGB Compressed PVRTC4. It was the default texture, and the script i made was taking it from an UI.Image. Then i upload it to a server, and that canvas isn't visible anyway at that moment. But when i enable that canvas... i download another texture from the server for that UI.Image.

The idea is that... the texture that i manually assigned to the UI.Image, looked exactly like your (report01-strech-scale.png). I selected the texture in the Project window and i changed the "Non Power of 2" propriety to "ToLarger". Your texture, is already set on "Advanced" when you make it in the script because otherwise it wouldn't be readable, so... I found here the propriety http://docs.unity3d.com/ScriptReference/TextureImporter.html http://docs.unity3d.com/ScriptReference/TextureImporter-npotScale.html

It's apparenrly called npotScale Just set it t "ToLarger" and it should be fine.

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 dee7800 · Oct 12, 2015 at 06:13 AM 0
Share

TextureImporter seems to be another class of object. I couldn't figure out how to incoperate npotScale. i am using objects of class Texture2D and RenderTexture and am not sure how they would interect with a TextureImporter class. I also am not doing any importing, only writing a file at the end.

i am using the ReadPixels with the texture2D and suppose to read from the RenderTexture which is suppose to be rendering to the target texture ins$$anonymous$$d of the screen at the moment. I feel the something is wrong with the rendering to texture and reading from it.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rendering an HD PNG off-screen? 0 Answers

Get image of 3d model 0 Answers

Save rendertexture to image in file 2 Answers

Better faster solution for ReadPixels? 0 Answers

scale squash rendertexture to different size 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