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
0
Question by adrianrdzv · Aug 18, 2011 at 08:15 AM · androidscreenshotencode

EncodeToPNG problem on Android?

I'm trying to capture a screenshot from my application running on Android using the standard code found in some examples:

 var width = Screen.width;
 var height = Screen.height;
 var tex = new Texture2D(width, height, TextureFormat.RGB24, false);

 tex.ReadPixels(Rect(0, 0, width, height), 0, 0);
 tex.Apply();

 var bytes = tex.EncodeToPNG();
 Destroy(tex);

 File.WriteAllBytes(Application.persistentDataPath + "/screenshot.png", bytes);

The file is created, but for some reason I cannot preview this file in Android. If I open it it shows as a corrupted file (black). I tried in a Galaxy Tab running android 2.2 and an Asus Transformer running 3.2.

If I preview the image from a computer it works. It seems to be a problem with a CRC calculation or bad length. I'm not sure, but the error is something that apparently in Windows is tolerable enough to show the file. Anybody who can help me with this issue?

Comment
Add comment · Show 6
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 Waz · Aug 18, 2011 at 04:49 PM 0
Share

If you generate the file in the Editor, is it then viewable on Android? i.e. is the problem specific to Android Unity, or to the Android image viewer?

avatar image adrianrdzv · Aug 19, 2011 at 08:29 AM 0
Share

If I generate the file in the Editor and then copy it to Android then it seems to be fine. The problem still occurs when the app is running on the phone and creates the file, it is created "corrupted".

avatar image maccoi · Sep 02, 2011 at 02:35 AM 0
Share

The same phenomenon has happened. It moved normally when returning it to Unity3.3 because it had been generated by Unity3.4. Bug of Unity3.4?

avatar image GlitchEnzo2 · Oct 03, 2011 at 06:07 PM 0
Share

I'm encountering the same issue, and it's definitely a CRC issue. I've called EncodeToPNG() on both the PC and Android, and then opened both resultant PNGs side by side in a hex editor. The only differences are the CRCs.

I filed a bug with Unity. http://fogbugz.unity3d.com/default.asp?421666_cjljpd4n037ipb2t

avatar image Waz · Oct 04, 2011 at 09:54 AM 0
Share

Can I place a bet on some code making assumptions about the signedness of char...

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Chris 48 · Mar 06, 2012 at 08:47 AM

try ReadPixels on OnPostRender not on Update/LateUpdate.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Screenshot is not save properly into the folder. 0 Answers

Screenshot 0 Answers

Screenshot function not working properly ,it records button on UI ? 0 Answers

How to use FB.Feed (not FB.API) in sharing a screenshot in picture parameter? 1 Answer

Open screenshot in file location Android 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