我们如何在Android中调整图片大小? [英] How do we resize images in Android?

查看:1155
本文介绍了我们如何在Android中调整图片大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在环顾四周,找不到对此的肯定答案。对于图像,我们是否使用硬编码的dp作为布局宽度和高度,还是使用wrap_content?例如,假设我有一个带有图标的imageview作为其图像。如果我使用wrap_content,图像太大,并且无法调整大小(图像是使用xxhdpi制作的)。如果我设置了dp manaully,那么如果它的屏幕较大(或者它,我不确定它是否仍然存在?),则图像不会随设备缩放。

I have been looking around and can't find a positive answer to this. For images, do we use hard-coded dp for the layout width and height or do we use wrap_content? For example, say I have an imageview with an icon as its image. If I use wrap_content, the image is too big, and there is no way to resize it (image was made using xxhdpi in mind). If I set the dp manaully then the image doesn't scale with the device if its screen is larger (or does it, I'm not sure if it still does?).

我想知道我们要遵循的工作流程,我已经阅读了所有文档,但在缩放图像方面却很模糊。我有各种屏幕尺寸(hdpi,mdpi等)的图像。

I want to know the workflow we're suppose to follow, I have read all the documentation but it's vague in terms of scaling images. I have an image for each of the various screen sizes (hdpi, mdpi, etc.).


  1. 如果我硬编码了宽度和高度, Android仍然使用那些
    图像(hdpi,mdpi等)用于不同的屏幕尺寸?

  1. If I hardcoded the width and height, does android still use those images (hdpi, mdpi, etc) for different screen sizes?

硬编码宽度和高度不好的做法,如果是这样的话什么是调整图像大小的
替代方法?

Is hardcoding the width and height bad practice, if so, what is the alternative to resizing the image?

如果我们硬编码每个屏幕分辨率的大小怎么办?因此,对于
的例子,我会使用200dp x 200dp的平板电脑和100dp x 100dp的
手机硬编码图像的宽度和高度。这是一个
好​​方法吗?

What if we hardcoded the size for each screen resolution? So for example, I would use 200dp x 200dp for tablets and 100dp x 100dp for phones when hardcoding the width and height of an image. Is this a good approach?

使用图像时最好的工作流程是什么?
我应该为每个屏幕分辨率创建不同大小的图像吗?
我应该使用一个大图像,然后对每个
布局进行硬编码吗?

What is the best workflow to follow when working with images? Should I create a different size of an image for each screen resolution? Should I use one large image and then hardcode the size for each layout?

有没有我可以提供图像的网站或程序,它会自动提供各种屏幕密度图像?例如,我上传了一张图片,它会为我提供mdpi,hdpi,hdpix等图片。我环顾四周,但只能找到符合图标的程序,而不是图像。

Is there a website or program in which I can provide an image and it automatically comes up with the various screen density images? For example, I upload an image and it will give me an mdpi, hdpi, hdpix, and etc images for it. I have looked around, but can only find programs that work with icons, not images.

推荐答案

你应该可以依赖Android系统适当地缩放你的图像。查看各种扩展方法的开发文档

You should be able to rely on the android system to scale your images appropriately. Check out the Dev docs for various scaling methods

http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

这篇关于我们如何在Android中调整图片大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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