如何在使用Android Universal Image Loader的视图中显示之前调整图片大小?

如何在使用Android Universal Image Loader的视图中显示之前调整图片大小?,第1张

概述我成功地将Universal Image Loader库(1.8.3版本)应用到我的应用程序中,并且我试图在将其显示在gridview项目之前调整图像大小(因为有时图像太大而无法将其缓存在内存中.) 这是我正在尝试的: ...BitmapFactory.Options resizeOptions = new BitmapFactory.Options();resizeOptions.inSam 我成功地将Universal Image Loader库(1.8.3版本)应用到我的应用程序中,并且我试图在将其显示在grIDvIEw项目之前调整图像大小(因为有时图像太大而无法将其缓存在内存中.)

这是我正在尝试的:

...BitmapFactory.Options resizeOptions = new BitmapFactory.Options();resizeOptions.inSampleSize = 3; // decrease size 3 timesresizeOptions.inScaled = true;options = new displayImageOptions.Builder().showStubImage(R.drawable.blank).showImageForEmptyUri(R.drawable.no_image).cacheInMemory().cacheOndisc().deCodingOptions(resizeOptions).build();...

由于某种原因,此代码不会使图像缩小3倍.

有人有更好的方法来按照指定的密度调整图像大小吗?

解决方法 认真阅读Java文档:

Options.inSampleSize of incoming options will NOT be consIDered. library calculate the most appropriate sample size itself according to imageScaleType(...) options.

另请查看定义图像目标大小的ImageSizeUtil.defineTargetSizeforVIEw(ImageVIEw imageVIEw,int maxImageWIDth,int maxImageHeight):

Size is defined by target vIEw parameters,configuration parameters or device display dimensions.
Size computing algorithm:

Get the actual drawn getWIDth() and getHeight() of the VIEw. If vIEw haven’t drawn yet then go to step #2. Get layout_wIDth and layout_height. If both of them haven’t exact value then go to step #3. Get maxWIDth and maxHeight. If both of them are not set then go to step #4. Get maxImageWIDth param (maxImageWIDthForMemoryCache) and maxImageHeight param (maxImageHeightForMemoryCache). If both of them are not set (equal 0) then go to step #5. Get device screen dimensions.

UIL根据imageScaleType和targetSize(以及ImageVIEw的scaleType)定义结果位图大小.

总结

以上是内存溢出为你收集整理的如何在使用Android Universal Image Loader的视图中显示之前调整图片大小?全部内容,希望文章能够帮你解决如何在使用Android Universal Image Loader的视图中显示之前调整图片大小?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1138468.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存