• 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 uryokesh · Nov 25, 2015 at 08:48 PM · runtimeruntime-generationbitmap

Creating bitmap texture2d during runtime

Hey All,

I have a need that my image will be downloaded to the application during runtime outside of the Application.dataPath (Assets folder) in bmp format. Using which I need to create my texture2D during run time. I am able to do this if the image is a png or jpg but not for a bitmap image. I am restricted to the fact that this image is going to be of bitmap format.

For JPG or Png I am able to create runtime texture2D using the following code

         CreateRunTimeTexture(string fileName)
         {
             byte[] pngBytes = System.IO.File.ReadAllBytes(fileName);
             Texture2D pngTexture = new Texture2D(74, 74, TextureFormat.RGB24, false);
             pngTexture.LoadImage(pngBytes);
         }

Since UnityEditor is able to handle bitmap images I believe what am trying to do is possible. Any help is much appreciated.

Code example pointed above is to show how am doing for png/jpg. If bitmap needs to be done through someother fashion thats is fine. Currently am not able to process the bitmap bytes properly to achieve the result I am looking for.

One hack suggested to me was to use a program during runtime to convert bmp to png and then load them in to texture and then delete the png. I am able to do this but if bmp could be directly loaded it would be great.

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 gjf · Nov 24, 2015 at 08:28 PM 0
Share

LoadImage only reads png/jpg

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Overwriting a prefab in runtime? 1 Answer

Modifying an heightmap at runtime 2 Answers

Gradual Terrain Smoothing from a Flat Area (at Runtime) 0 Answers

what is the best way to implement minigames into my own full blown unity game. 0 Answers

How to create road or buildings during running the game 2 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