问题
I want to download an image from the 'net and set it as the users background. This works great over wi-fi, and some 3G networks, but others (T-Mobile UK, for sure) seem to compress the images before sending them.
This effect is noticeable when using the browser, too - however, if you long press on an image and save it, when viewing in the gallery it is either not compressed at all, or substantially less so. I want to be able to do this in my own app.
I assume it has something to do with the HTTP headers, but of the ones I've modified, none has made a difference.
Can anyone help me out here?
Similar question here Android: BitmapFactory.decodeByteArray gives pixelated bitmap but is unresolved.
回答1:
Have you tried setting a no-cache header? This may work on some networks.
You can also try having the client request the image a second time, this also may skip the compression.
回答2:
Some 3G networks are compressing the images to save bandwith. Sometimes they do not even honor no cache http header. To bypass them, you can
- inline base 64 your image using data-uri
- serve them as https or via a non standard http port
Full discussion about it : http://blog.sebcante.com/2012/01/prevent-image-compression-from-3g.html
回答3:
Setting a no-cache
header has stopped working on some providers like Vodafone Germany a few years ago.
Instead these providers offer a webinterface where you can adjust the settings yourself. For Vodafone Germany just go to performance.vodafone.de and you will be greeted with the basic settings dialogue, but you can also choose the option "expert settings" for a more fine grained control and advanced options.
Links for different providers and countries or whole lists are very much welcome!
回答4:
If you have control over the image the user downloads, you may want to put it into a ZIP file including your image, have your code unpack the image, and set it as the background. You would be sure no network apply any degradation this way.
But of course, if you don't have control over the gallery the user can select from, this solution is not applicable...
来源:https://stackoverflow.com/questions/3171056/avoiding-image-compression-on-some-3g-networks