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 Karmate · Oct 09, 2017 at 11:55 AM · androidimagesavegallerysave file

how to save compressed image to gallery on Android ?

Hello, this code is working great with rgb color images, how can i make this work with compressed images?

 private const string MediaStoreImagesMediaClass = "android.provider.MediaStore$Images$Media";
 
     public static string SaveImageToGallery (Texture2D texture2D, string title, string description)
     {
         using (var mediaClass = new AndroidJavaClass (MediaStoreImagesMediaClass))
         {
             using (var cr = Activity.Call<AndroidJavaObject> ("getContentResolver"))
             {
                 var image = Texture2DToAndroidBitmap (texture2D);
                 var imageUrl = mediaClass.CallStatic<string> ("insertImage", cr, image, title, description);
                 return imageUrl;
             }
         }
     }
 
     public static AndroidJavaObject Texture2DToAndroidBitmap (Texture2D texture2D)
     {
         byte[] encoded = texture2D.EncodeToJPG ();
         using (var bf = new AndroidJavaClass ("android.graphics.BitmapFactory"))
         {
             return bf.CallStatic<AndroidJavaObject> ("decodeByteArray", encoded, 0, encoded.Length);
         }
     }
 
     private static AndroidJavaObject _activity;
 
     public static AndroidJavaObject Activity {
         get {
             if (_activity == null)
             {
                 var unityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
                 _activity = unityPlayer.GetStatic<AndroidJavaObject> ("currentActivity");
             }
             return _activity;
         }
     }
Comment
Add comment · Show 2
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 sieutungbi · Oct 19, 2017 at 09:30 AM 0
Share

hi , can you show me your " create image function " i try to create and save image using this method , but still not working . thank you

avatar image Karmate sieutungbi · Oct 19, 2017 at 09:33 AM 0
Share

Just call "SaveImageToGallery" function. You must add write_external_storage permisssion to manifest file.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Karmate · Oct 10, 2017 at 09:35 AM

still looking for answer, can't find a good solution for this problem.

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

152 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 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 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 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 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 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 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 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 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

Download Image to a new album (Android) 0 Answers

[Edited]Access photos from gallery in application (Android) 1 Answer

Save File for Android Game.. 2 Answers

Save a Texture2D for android 1 Answer

pick image from android gallery 3 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