简体   繁体   English

(Android) 使用透明背景调整图像大小?

[英](Android) Resizing images with a transparent background?

I'm getting images through an API, except the problem is that all the images are in a fixed size, which leaves large pictures okay since it takes up the whole space, but there are some pictures with small objects, as shown here我正在通过 API 获取图像,但问题是所有图像的大小都是固定的,这使得大图片没问题,因为它占据了整个空间,但是有些图片带有小物体,如下所示

image_large image_large

I was wondering if there is a way to detect if an image with a transparent background can be resized to only what's shown such as here我想知道是否有一种方法可以检测具有透明背景的图像是否可以调整为仅显示的大小,例如此处

image_small image_small

The libraries I'm using for this are glide to get the images from a URL and GifImageView to hold the image.我为此使用的库是 glide 从 URL 和 GifImageView 获取图像以保存图像。 Any help would be appreciative.任何帮助将不胜感激。

I think that scalingtype attribute will be helpful.我认为 scaletype 属性会有所帮助。 And with glide, there is a method called apply() that you can use it to determine the option that you can use to modify you imageView使用 glide,有一个名为 apply() 的方法,您可以使用它来确定可用于修改 imageView 的选项

RequestOptions cropOptions = new RequestOptions().centerCrop(context); RequestOptionscropOptions = new RequestOptions().centerCrop(context); ... Glide.with(fragment) .load(url) .apply(cropOptions) .into(imageView); ... Glide.with(fragment) .load(url) .apply(cropOptions) .into(imageView); You can benefit from the documentations of glide library您可以从 glide 库的文档中受益

https://bumptech.github.io/glide/doc/options.html https://bumptech.github.io/glide/doc/options.html

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

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