如何在运行时为不同屏幕调整图像大小? [英] How to resize images at runtime for different screens?

查看:40
本文介绍了如何在运行时为不同屏幕调整图像大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在 Android Studio 中有一些插件可以包含一个 drawable,这些插件有助于创建 ldpi、mdpi、hdpi 等图像资源.

I know that in Android Studio there are some plugins for including a drawable that help in creating a ldpi, mdpi, hdpi, etc image resource.

但是假设我有一个应用程序,其中一些用户将图像上传到服务器,然后我下载图像并将它们显示给其他用户,我该如何调整它们以使它们适应 ldpi、mdpi、hdpi 屏幕?是否有在服务器或客户端上运行的库?

But suppose I have an app in which some users upload images to a server and then I download the images and display them for other users, how can I adapt them so that they adapt to ldpi, mdpi, hdpi screens? Is there a library that runs on the server or client?

推荐答案

有两种方法,要么自己做,要么让别人做

there are two ways , either you do it or let other do it

  1. 您可以使用带有 fit 功能的 picasso(图像加载库),然后放松一下.链接

  1. you can use picasso(image loading library ) with fit function and just relax .link

找到所需的尺寸并使用所需的参数压缩图像尺寸.安卓指南

find the required size and compress the image size with required parameter.android guide

虽然 picasso 和 glide 最受安卓开发者欢迎,但还有其他一些库,如 picasso、glide、通用图像加载器等

there are couple of other library like picasso,glide,universal image loader and lot other though picasso and glide are most popular among android developers

代码参考链接:

毕加索

用于下载图像的毕加索库

将图像调整为全宽和固定高度毕加索

滑翔

使用 Glide 从 SD 卡加载图像

库的优点:

  • 内置图像下载机制,具有动画、调整大小等其他功能
  • 内置缓存机制
  • 由经验丰富的程序员优化编写的代码
  • 可以从资源等加载图像到位图
  • 动画支持

缺点:

  • 与文档保持联系以获取新的更新和更一致的功能

这篇关于如何在运行时为不同屏幕调整图像大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆