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
4
Question by alok-kr-029 · Apr 02, 2015 at 12:28 PM · spritetexture2druntimeconvert

Convert Texture2d to sprite

Hi I am having a png file downloaded from server. I have to create a sprite at run time out of texture is there any easy method to do this

   public SpriteRenderer bg;
     
 void change()
 {
 Texture2D sprites = Resources.Load<Texture2D>("lev1/"+name[i]) ;
                 Rect rec = new Rect(0, 0, sprites.width, sprites.height);
                 Sprite.Create(sprites,rec,new Vector2(0,0),1);
                 bg.sprite = Sprite.Create(sprites,rec,new Vector2(0,0),.01f);}


I used this code but the sprite that is formed is very large than expected As i change this texture to sprite from the inspector and then drag and drop this sprite set my camera according to it and and then change the back sprite to texture and use the I code to convert the texture to sprite I get different result ...

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

Answer by blueteak · Apr 02, 2015 at 01:40 PM

You have the right implementation, use Texture2D.Resize to get it smaller.

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
avatar image
0

Answer by NinjaISV · Sep 11, 2015 at 03:44 PM

This article will probably solve your issue: http://answers.unity3d.com/questions/650552/convert-a-texture2d-to-sprite.html

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 hauzz · Nov 19, 2015 at 08:47 AM 0
Share

But I use Rect rec = new Rect(0, 0, texture.width, texture.height);

dust.GetComponent ().sprite=Sprite.Create(texture,rec,new Vector2(0.5f,0.5f),100);

But result is image became small than before sprite.

Someone know how to solve.

Thanks for the help!

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

22 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

Related Questions

Can I create a sprite at runtime? 3 Answers

Using Texture2D created at runtime to create a Sprite decreases Sprite quality. (Android) 1 Answer

Convert texture 2d to sprite and save 0 Answers

Change SpriteRenderers Texture2D in runtime 1 Answer

White Edges on Sprites Loaded from PNG at Run-time 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