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 /
  • Help Room /
avatar image
1
Question by robdeja · May 24, 2016 at 09:25 AM · texture2dwrapmodeexternal assetsfiltermode

Texture2d load from disk - set filtering

I'm new to Unity so might be doing something wrong but I'm using the following function to load an external image but the problem is, I cannot seem to set filtering or wrap mode - it always displays jaggy and wrapped.

 public static Texture2D LoadImg(string filePath)
     {
         //load image from disk as Texture2d
         Texture2D tex = null;
         byte[] fileData;
 
         if (File.Exists(filePath))
         {
             fileData = File.ReadAllBytes(filePath);
             tex = new Texture2D(2048, 2048,  TextureFormat.RGB24, false);
             tex.LoadImage(fileData);
             tex.filterMode = FilterMode.Trilinear;
             tex.wrapMode = TextureWrapMode.Clamp;
             tex.anisoLevel = 16;
             tex.Apply(); //needed?
         }
         return tex;
     }
 
 //call the external image loader and apply it to gameObject
 myMats[0].mainTexture = LoadImg(mypath + "/01.jpg");

I want to display the external jpeg image as high quality as possible in game. Any ideas?

Comment
Add comment · Show 5
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 saud_ahmed020 · May 24, 2016 at 09:38 AM 0
Share

@robdeja
Just use following code to load Texture

 Texture2D textureName;
  
  void Start () 
  {
  textureName = (Texture2D)Resources.Load("Resources/yourTextureName");
  }
  renderer.material.mainTexture = textureName;
avatar image robdeja saud_ahmed020 · May 24, 2016 at 09:52 AM 0
Share

Thanks for the reply but I cannot do this (as far as I know). I am loading an external image not packaged with the game, it's a file on the android file system (photos).

avatar image robdeja · May 24, 2016 at 01:02 PM 0
Share

Update I have had some success in changing the following to allow it to generate mipmaps

 tex = new Texture2D(2048, 2048,  TextureFormat.RGB24, true);

Filtering now seems to work and the texture is not aliasing which is good, but it is now slightly blurry.
I've played with mip$$anonymous$$apBias but it's not increasing sharpness. $$anonymous$$y original texture is 2048px but it looks like it's much lower when shown in game - I'm always at a fixed distance from these textures (pretty close) so using mipmapping is a bit redundant in my case, but it does help with the texture filtering.

Any suggestions?

avatar image saud_ahmed020 robdeja · May 24, 2016 at 01:23 PM 0
Share

@robdeja Did you try TextureFormat.RGBA32 ?? Try it if not tried it.

avatar image robdeja saud_ahmed020 · May 24, 2016 at 01:33 PM 0
Share

yes I tried that, no difference.

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

58 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

Related Questions

TextureWrapMode repeats despite UV being 1 0 Answers

Trying to create a freaking math clone. new learner and very low coding skills. Having trouble with setting the time limit for the process.Need Help? 1 Answer

SetPixels edge pixels 0 Answers

Unity seems to be in 2D, but I want it in 3D 1 Answer

Mix Shaders Question -- Multiple Textures, Recolorable? 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