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 adrenak · Jul 16, 2013 at 04:55 PM · assetscreenshotcapturescreenshot

Allow user to download images from game assets

HI,

I am a working on an Android project, which is almost over, except for one feature that I want to add to the game. I want the player to be able to download some wallpaper images that is included in the the projects asset, just as bonus content. First I thought of displaying the images as GUITexture and then saving screenshots using Application.CaptureScreenShot(), but it doesn't seem to work. There are some work around for taking screenshots that I came across online.

However, I think that a better solution would be to copy the asset file, i.e. the .jpg wallpapers to the SDCard of the user or maybe internal storage, as screenshot might have encoding issues also. Can this be done, without too much complications?

Thanks, Vatsal Ambastha

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 raphaeltom · Jul 16, 2013 at 10:51 PM 1
Share

You could save the wallpapers under a Resources folder, something like Assets/Resources/Wallpapers. Then, at runtime, you could list all the wallpapers there by calling Resources.LoadAll("Wallpapers", typeof(Texture2D)).

As for saving the files on the SD card, I'm sure there's a way, but I wouldn't know how.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Jul 17, 2013 at 04:36 AM

Re: Application.CaptureScreenShot() - are you sure you have permission to write the file at the location you specify? You should be able to write the file at Application.persistentDataPath. This doesn't necessarily solve your problem of providing the image for the user. I don't know how the sandboxing on Android works, but you'll likely have to provide a plugin to move the file to the gallery or some other place you have permission. Prime31's Etcetera plugin has a saveImageToGallery() method that should allow you to move the file.

As for getting the bytes to begin with you have a couple of choices beyond CaptureScreenShot(). If you want to use a texture in your app, you can use Texture2d.EncodeToPNG() to create the PNG, and then use File.WriteAllBytes() to write the file wherever you have permission.

Another option is to store the file in your resources directory as a TextAsset. Change the file extension of the image file to .bytes. So 'image.png' becomes 'image.bytes', and then drag and drop it into the Resources folder. To write the image out you can do:

 var image = Resources.Load(filename) as TextAsset;
 File.WriteAllBytes(Application.persistentDataPath+"/"+filename+".png", image.bytes); 

Where filename would be the name of the file without the ".bytes" extension.

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 adrenak · Jul 17, 2013 at 08:09 AM 0
Share

thanks! I will have a look into this +1

avatar image
0

Answer by Benproductions1 · Jul 17, 2013 at 04:32 AM

http://lmgtfy.com?=Unity+Save+Texture+to+file

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 flamy · Jul 17, 2013 at 05:01 AM 0
Share

haha nice one!

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

16 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

Related Questions

Screenshot is not saving to Gallery and folder 2 Answers

Saving Path for Screenshot 1 Answer

How to save a screenshot to the camera roll (picture gallery)? 3 Answers

Capturing 360 Image causes to darken the image and show ghosting and artifacts 0 Answers

[TIZEN] Application.CaptureScreenshot doesnt work 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