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 imjusthere · May 10, 2017 at 01:36 PM · texturespritewww classthumbnails

using www to fill scrollarea

I am trying to find all the images on an android device and create thumbnails for them and then put them into a scroll area. I can find the paths to the images but when I create the thumbnails the app either gets really choppy or freezes completely until it's finished. What is the correct way to do this?

Here is what I've tried:

 //this one freezes it for a while
 Sprite newSprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));
 newThumbnail.GetComponent<Image>().sprite = newSprite;

And

 //this one make is really choppy
 Texture2D tex = new Texture2D(www.texture.width, www.texture.height);
 www.LoadImageIntoTexture(tex);
 newThumbnail.GetComponent<RawImage>().texture = tex;


Comment
Add comment · Show 3
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 ben-rasooli · May 10, 2017 at 02:00 PM 0
Share

What do you mean by all images? I can only see one image here www.texture. Where are the rest? How to you get and store them? This code looks alright. The problem must be somewhere else.

avatar image imjusthere ben-rasooli · May 10, 2017 at 02:43 PM 0
Share
   IEnumerator GetAllGalleryImagePaths()
         {
             HashSet<string> allowedExtesions = new HashSet<string>() { ".png", ".jpg", ".jpeg"};
             debugText.text = "starting coroutine";
             #if UNITY_ANDROID
     
                 AndroidJavaClass mediaClass = new AndroidJavaClass("android.provider.$$anonymous$$ediaStore$Images$$$anonymous$$edia");
     
                 // Set the tags for the data we want about each image.  This should really be done by calling; 
                 //string dataTag = mediaClass.GetStatic<string>("DATA");
                 // but I couldn't get that to work...
     
                 const string dataTag = "_data";
     
                 string[] projection = new string[] { dataTag };
                 AndroidJavaClass player = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                 AndroidJavaObject currentActivity = player.GetStatic<AndroidJavaObject>("currentActivity");
     
                 string[] urisToSearch = new string[] { "EXTERNAL_CONTENT_URI", "INTERNAL_CONTENT_URI" };
                 foreach (string uriToSearch in urisToSearch)
                 {
                     AndroidJavaObject externalUri = mediaClass.GetStatic<AndroidJavaObject>(uriToSearch);
                     AndroidJavaObject finder = currentActivity.Call<AndroidJavaObject>("managedQuery", externalUri, projection, null, null, null);
                     bool foundOne = finder.Call<bool>("moveToFirst");
                     while (foundOne)
                     {
                         yield return null;
                         int dataIndex = finder.Call<int>("getColumnIndex", dataTag);
                         string data = finder.Call<string>("getString", dataIndex);
                         if (allowedExtesions.Contains(Path.GetExtension(data).ToLower()))
                         {
                             string path = @"file:///" + data;
                             StartCoroutine(CreateImage(path));
                         }
     
                         foundOne = finder.Call<bool>("moveToNext");
                     }
                 }    
     #endif
     
         }
     
         IEnumerator CreateImage(string path)
         {
             WWW www = new WWW(path);
             yield return www;
     
             //Sprite newSprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));
             GameObject newThumbnail2 = Instantiate(videoThumbnailPrefab) as GameObject;
             Texture2D tex = new Texture2D(www.texture.width, www.texture.height);
             www.LoadImageIntoTexture(tex);
             newThumbnail2.GetComponent<RawImage>().texture = tex;
             newThumbnail2.transform.parent = imageContentHolder;
             newThumbnail2.transform.localScale = Vector3.one;
             newThumbnail2.transform.position = imageContentHolder.transform.position;
         }
 
 
avatar image imjusthere ben-rasooli · May 10, 2017 at 02:46 PM 0
Share

There is all my code and it's working fine. The issue is that creating the sprite or texture2D is very slow. If I create sprites it freezes the app for about .25 seconds per image. If I create texture2Ds it doesn't completely freeze but it gets really choppy. It's a Gear VR app so I need to avoid the choppiness as much as possible.

0 Replies

· Add your reply
  • Sort: 

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

UI Sprite very pixelated 1 Answer

Mask a texture onto sprite? 0 Answers

Created Material Shows Dark Sprite 1 Answer

Sprite rendering texture as one solid color 1 Answer

Bad quality of the sprite in Unity 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