简体   繁体   English

API-iOS和Android的图片大小(不同的屏幕大小)-优化

[英]API - Image Sizes for iOS and Android (Different Screen sizes) - Optimization

Working on an Application that displays images in various sizes as grids, lists (Instagram like), images that take up the whole screen. 在一个应用程序上工作,该应用程序将各种大小的图像显示为网格,列表(类似于Instagram)和占据整个屏幕的图像。

Ex. 例如 - you might have is a grid view image (not very big), but also this same image is shown in another screen that's almost the size of the entire screen. -您可能有一个网格视图图像(不是很大),但是在另一个屏幕中也显示了相同的图像,该图像几乎是整个屏幕的大小。 It's like a blown up version of this. 这就像一个炸毁的版本。 There are also the smaller thumbnails of these images. 这些图像也有较小的缩略图。

Working with the Backend team to come up with an optimal solution. 与后端团队合作,提出最佳解决方案。

Questions: 问题:

  1. What's the most optimal way to handle images for different screen sizes? 处理不同屏幕尺寸的图像的最佳方法是什么? I know instagram sends the URLs for high resolution low resolution and thumbnails. 我知道instagram发送的是高分辨率,低分辨率和缩略图的URL。

  2. Do we need multiple sizes for each image? 每个图像需要多个尺寸吗? example. 例。 grid view (do we need a 1x, 2x or 3x) for each image?. 每个图像的网格视图(我们需要1x,2x还是3x)? or can one size serve all phone screen sizes and we can just set the scale mode in code? 还是一种尺寸可以满足所有手机屏幕尺寸,而我们只需在代码中设置缩放模式即可? Would this be ok even for smaller screen sizes? 即使较小的屏幕尺寸也可以吗? Would this be a poor experience for smaller phone sizes since they need images. 对于较小尺寸的手机,这会是不好的体验,因为它们需要图像。 To me this wouldn't be optimal since smaller phones like SE don't have the same processing power as iPhone 8 plus. 对我来说,这不是最佳选择,因为SE等较小的手机没有与iPhone 8 plus相同的处理能力。

  3. If we're using the same API to serve iPhone and Android - how can this api be leverage for android given that they have more image sizes to handle. 如果我们使用相同的API来为iPhone和Android服务-鉴于它们需要处理更多图像大小,那么该api如何成为Android的杠杆。

Any guidance would be greatly appreciate it. 任何指导将不胜感激。

PREMISE: 前提:

You are talking about images from web server. 您正在谈论来自Web服务器的图像。 Not svgs, not interface graphics. 不是svgs,不是界面图形。 There's no official documents of this field, just suppositions and results of experience. 该领域没有正式文件,只是假设和经验结果。 I'm sharing mine. 我在分享我的。

If you meant interface graphics, there are official documentations from Apple and Google. 如果要使用界面图形,则有Apple和Google的官方文档。 If you meant svgs, they're automatically scaled. 如果您的意思是svg,它们会自动缩放。 If you intended to have answer for those, please edit the topic or open new ones 如果您希望得到这些答案,请编辑主题或打开新主题

A solution could be, instead of acting only on images sizes, to change the quality of JPGs. 解决方案可以改变JPG的质量,而不是仅作用于图像大小。

You can use a full quality ~200x~200 image for little thumbnails (avatars, photo icons), which could be ok for all devices sizes, resolutions and models, without being too heavy. 您可以使用高质量的〜200x〜200图像作为小缩略图(头像,照片图标),这对于所有设备尺寸,分辨率和型号都可以,而且不会太重。

Then, for bigger previews/full image opened you could maintain the same size (the original one, or a maximum size you define) but, using two version of the image: one with little JPG quality (so that it can be loaded quickly, consume less bytes and show the image content) and the other with the original quality (which requires loading and bytes, but it's only shown by demand). 然后,对于较大的预览/打开的完整图像,您可以保持相同的尺寸(原始尺寸,或者您定义的最大尺寸),但是要使用两种版本的图像:一种版本的JPG质量较低(以便可以快速加载,消耗较少的字节并显示图像内容),而另一种具有原始质量(需要加载和字节,但是仅按需显示)。

To choose the right value of the little thumbnail (the ~200px), check the bigger thumb size you have. 要选择小缩略图的正确值(约200像素),请检查较大的拇指尺寸。 If you have an avatar bubble which is 96x96 on smallest res, multiply it for 3 (96*3=288) and you have the size! 如果您的头像气泡在最小分辨率上为96x96,则将其乘以3(96 * 3 = 288),您就可以拥有它的大小! It is true that the smallest res screen will only require a 96x96 image, but, given that those are little numbers, the difference is not relevant (also, because we are talking about photos and not vectorial images, if you scale manually or if you leave the scaling to the device, the result is the same). 的确,最小的分辨率屏幕仅需要96x96的图像,但是鉴于这些数字很小,因此两者之间的差异并不重要(而且,因为我们是在谈论照片,而不是矢量图像,如果您手动缩放或将缩放比例留给设备,结果是相同的)。

I've found some documentation from Google, which explains some things about image formats and how to reduce download sizes: https://developer.android.com/topic/performance/network-xfer.html They say to use JPEGs, PNGs, or WebPs and show some examples and guidelines for choosing the right format 我从Google找到了一些文档,其中解释了有关图像格式以及如何减少下载大小的一些内容: https : //developer.android.com/topic/performance/network-xfer.html他们说要使用JPEG,PNG,或WebP,并显示一些示例和准则以选择正确的格式 Google的格式选择

You can use svg resources(which is a vector-based-image) : By doing so, you don't need to generate a resource for each resolution, and just need 1 resource. 您可以使用svg资源(这是基于矢量的图像):这样,您无需为每个分辨率生成一个资源,只需要一个资源即可。 In realtime, the svg image will expand to the resolution of the device. 实时,svg图像将扩展到设备的分辨率。

According to the documentation, you have a lot to gain here : 根据文档,您在这里有很多收获:

Using vector drawables instead of bitmaps reduces the size of your APK because the same file can be resized for different screen densities without loss of image quality 使用矢量绘制而不是位图可以减小APK的大小,因为可以为不同的屏幕密度调整同一个文件的大小,而不会降低图像质量

I have used this in Android, and it solves your issue in Android. 我已经在Android中使用了它,它可以解决Android中的问题。

I Haven't used this in iOS but, it looks like there's a similar solution as well. 我还没有在iOS中使用它,但是看起来也有类似的解决方案

Your all questions are nearly have same goal. 您所有的问题几乎都有相同的目标。 So Basically save 6 versions of images like 50px 100px 200px 400px 800px and 1600px etc. 因此,基本上可以保存6个版本的图片,例如50px 100px 200px 400px 800px和1600px等。

6 will be enough since you can cover nearly all screen sizes like google does in android. 6就足够了,因为您可以像google一样在Android中覆盖几乎所有屏幕尺寸。 which is ldpi mdpi hdpi xhdpi xxhdpi and xxxhdpi 这是ldpi mdpi hdpi xhdpi xxhdpi和xxxhdpi

Use an API for picture requests, send your screen sizes to api as parameter then give back resulting images width and height . 使用API​​进行图片请求,将屏幕尺寸发送给api作为参数,然后返回结果图像的widthheight for ex: for a 800x600 screen send back 400px version of it. 例如:对于800x600的屏幕,请传回其400px版本。

If you not do so, you will have to resize them on client size which is bad for performance and also bad approach for auto layout in IOS. 如果不这样做,则必须根据客户端大小调整它们的大小,这对性能不利,对于IOS中的自动布局而言也不利。

You can use third party image managing solutions like Cloudinary. 您可以使用Cloudinary之类的第三方图像管理解决方案。

https://cloudinary.com/ https://cloudinary.com/

Cloudinary generates images of different aspect ratio which can be serve to all types of devices. Cloudinary生成不同宽高比的图像,可用于所有类型的设备。

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

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