Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by NickP_2 · Feb 15, 2016 at 11:01 AM · texture2dcompressionudp

How to reduce an image to the most smallest size possible

Hello,

I'm not that familiar with compression types in Unity. I'm looking for a way to compress an image created on runtime to the smallest size possible, so it can be send over a local network using UDP. I also want to keep the quality to HD.

Right now I'm just using

Texture2D.EncodeToJPG()

But is there a more efficient way?

Thanks a lot!

Comment
Add comment · Show 1
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 adagne16 · Mar 28, 2021 at 10:30 PM 0
Share

Hey, did you ever find a solution? I am trying to send an image that the player takes over the network so I need to compress it but I could not find a good way to do so.

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by NickP_2 · Feb 16, 2016 at 09:40 AM

So, as for now, what I did:

  1. Encode Texture2D to byte array.

  2. Compress byte array using a compression script found here (This is actualy a pretty good life saver, as it works fast and efficient, even on mobile

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 MarkoHazel · Aug 05, 2020 at 11:51 PM 0
Share

Do you have a sample of your code? I'm using the algorithm to upload JPGs into a game and it's compressing by maybe 10-20%. I just wondering if this can be taken further to allow me to increase the quality of the image.

avatar image
2

Answer by phil_me_up · Feb 15, 2016 at 02:03 PM

To get it down to the smallest possible fixe size, you'll want to look at the compression options by either setting the quality in EncodeToJPG(x) or by calling .compress.

Compression will actually depend on what the image is. In some cases JPG will be better, in others PNG. You might be able to apply other compression too by setting the format, but again the best format and method depends on the quantity of the image (you don't want to go compressing something with gradients as PVR for example).

You might find that if you're letting the player create the image through some sort of pain, you're better off sending data which describes this image in a way your game can understand, which will often be much more efficient.

Finally, I assume you're aware that sending via UDP will have it's flaws. If there is any noise or data loss / corruption in the stream then the data you receive may not be readable, or if it is may have errors. TCP has error checking at its core (which is why in most cases it is a bit slower). UDP works in cases like character movement because you can perform filtering / smoothing / validation as you receive packets.

Comment
Add comment · Show 3 · 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 NickP_2 · Feb 15, 2016 at 05:17 PM 0
Share

Thanks for the reply,

I'm using this for sharing a camera view, so I can take a few frame losses :)

I basically already applied what you described (but unknowningly) so thanks for figuring that out!

Now, it would be awesome to compress the byte array, I found a few compression libraries, bit somehow my byte array got bigger ins$$anonymous$$d of smaller. I don't think it's possible to compress a compressed image byte array, or am I wrong?

avatar image phil_me_up NickP_2 · Feb 15, 2016 at 05:31 PM 0
Share

If you're sharing a camera view, a better way might be to simply transmit the parameters of the camera across the network (position, fov, clipping planes etc) and have some camera on the received end adopt those parameters (i.e. Player1 camera position etc gets sent to Player2. Player2 main camera (or some other camera) then adopts those positions and they will then see the same thing)

Doing this would be ALOT more efficient and allow you to compensate for data loss.

avatar image NickP_2 phil_me_up · Feb 15, 2016 at 06:13 PM 0
Share

that is indeed a good solution, altho I don't have the resources on the other client. I have to rely on images over the network :/

avatar image
0

Answer by BennyBurke · Aug 13, 2020 at 09:43 AM

You might find that if you're letting the player create the image through some sort of pain, you're better off sending data which describes this image in a way your game can understand, which will often be much more efficient.

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

38 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

Related Questions

Issues getting WWW.LoadImageIntoTexture to use DXT1 compression at runtime 0 Answers

How can I change the default max size of a texture from an editor script (in import settings)? 1 Answer

Does Unity decompress Truecolor RGBA format textures when loading? 0 Answers

Texture Compression format for UWP,Texture 0 Answers

Only RGBA32bit works when setting Texture2D pixels on iOS? 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