简体   繁体   English

在 flutter 中控制网络图像质量

[英]Control network image quality in flutter

I am building a flutter ebook app.我正在构建一个 flutter 电子书应用程序。 When the user is reading, the images take quite a while to load since they are over 1 mb in size.当用户阅读时,图像需要很长时间才能加载,因为它们的大小超过 1 mb。 This is not a problem for most users with a decent internet connection, but for many others it is.对于大多数拥有良好互联网连接的用户来说,这不是问题,但对于其他许多人来说却是。 Is it possible to control the quality of the image when being loaded from the internet by controlling how much to download, similar to when you search google images and the images progressively become more vibrant and their resolution increases,but in my case I stop it at a certain quality decided by the user.是否可以通过控制下载量来控制从互联网加载图像的质量,类似于当您搜索谷歌图像并且图像逐渐变得更有活力并且它们的分辨率增加时,但在我的情况下我停止它由用户决定的一定质量。 Thank you.谢谢你。

It sounds like you need to solve this on the server side and have an option in the Flutter app to choose the quality.听起来您需要在服务器端解决这个问题,并在 Flutter 应用程序中有一个选项来选择质量。 An example would be to have 5 versions of each image at 5 quality levels and let the user choose the quality level.例如,每个图像有 5 个版本,有 5 个质量级别,并让用户选择质量级别。 You can then have a quality parameter in the url you fetch images from.然后,您可以在从中获取图像的 url 中有一个质量参数。 Let's say that the user wants page 12 of a book with a quality level of 2, the url can be something like "https://mybackend.com/book-title/12/2".假设用户想要质量级别为 2 的书的第 12 页,url 可以类似于“https://mybackend.com/book-title/12/2”。

Implementing this solely in Flutter won't solve the internet issue.仅在 Flutter 中实现这一点并不能解决互联网问题。 The app will still download a 1MB image and then you could compress it before showing it but that won't matter.该应用程序仍将下载 1MB 的图像,然后您可以在显示之前对其进行压缩,但这并不重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM