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 BillyMFT · Jul 09, 2013 at 03:46 PM · iosscreenshotresize

resize screenshot

I am taking a screenshot in my iPad game with

Application.CaptureScreenshot( screenshotFilename );

this is later uploaded to social media sites. Works fine on older iPads but the uploads time out on an iPad 4, which I assume is due to the retina screen and the larger screenshot file size. So, how can I overwrite the screenshot with a png that is 1024x768?

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

2 Replies

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

Answer by DavidDebnar · Jul 09, 2013 at 05:35 PM

Use the javascript version of the TextureScale plugin. Just copy the code and paste it into TextureScale.js anywhere in your project.

TakeScreenShot method:

 import System.IO;
 
 function TakeScreenShot (name : String) {
      yield WaitForEndOfFrame(); // this also captures gui, remove if you don't wanna capture gui
      var shot = new Texture2D(Screen.width,Screen.height,TextureFormat.RGB24,false);
      shot.ReadPixels(Rect(0,0,Screen.width,Screen.height), 0, 0, false); 
      if(shot.width > 1024 || shot.height > 768)
           TextureScale.Bilinear(shot,1024,(1024.0/parseFloat(Screen.width))*Screen.height);
      //shot.Apply(); //this is unecessary, if you don't wanna use the image afterwards
      var bytes = shot.EncodeToPNG();
      var file = new File.Open(Application.persistentDataPath + "/" + name + ".png", FileMode.Create);
      var binaryWriter = new BinaryWriter(file);
      binaryWriter.Write(bytes);
      file.Close();     
 }

Usage

 function Start () {
      TakeScreenShot("screenShot"+System.DateTime.Now.ToString("-MM-dd-yyyy--hh-mm-ss"));
      Debug.Log(Application.persistentDataPath);
 }


Comment
Add comment · Show 5 · 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 BillyMFT · Jul 09, 2013 at 11:48 PM 0
Share

thanks - this looks very promising. I can post the image to social media now, but the image just contains a solid block of colour. Any idea what could be causing this?

avatar image DavidDebnar · Jul 10, 2013 at 12:15 AM 0
Share

Yes. Just uncomment //shot.Apply() and it should work.

avatar image BillyMFT · Jul 10, 2013 at 12:24 AM 0
Share

just tried the js version of the TextureScale class and it works! Thanks so much.

PS Apply() wasn't required

avatar image BillyMFT · Jul 10, 2013 at 12:25 AM 0
Share

PPS import System.IO; required in script that has TakeScreenShot function

avatar image DavidDebnar · Jul 10, 2013 at 09:29 AM 0
Share

Right, sorry, I forgot to include that.

avatar image
0

Answer by Jamora · Jul 09, 2013 at 04:50 PM

I haven't tried this personally, so it could scale the image, or just clip it. First, take the screenshot, then load it like explained here http://answers.unity3d.com/questions/14587/load-texture-at-run-time-from-file.html . Finally, use Texture2D.Resize() http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.Resize.html.

Comment
Add comment · Show 2 · 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 BillyMFT · Jul 09, 2013 at 11:48 PM 0
Share

thank you. Going to try $$anonymous$$'s first and will try this if I can't get it going.

avatar image DavidDebnar · Jul 10, 2013 at 12:21 AM 0
Share

Texture2D.Resize returns an undefined image, so it won't work.

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

17 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

Related Questions

How do i get screenshots for apple submission? 3 Answers

Running Camera roll from unity app 0 Answers

Share Screenshot Image to Facebook with Facebook SDK 0 Answers

Strange error uploading screenshots to iTunes Connect 0 Answers

How to wait till the screenshot is saved? 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