Android的通用图像装载机,displaing它在一个视图之前调整图片 [英] Android Universal Image Loader, resize picture before displaing it in a view

查看:133
本文介绍了Android的通用图像装载机,displaing它在一个视图之前调整图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功应用的通用图像装载机库(1.8.3版本)到我的应用程序,并试图在GridView的项目显示它之前调整图像大小 (因为有时图片太大缓存在内存中),在这里我想做:

  ...
BitmapFactory.Options resizeOptions =新BitmapFactory.Options();
resizeOptions.inSampleSize = 3; //减小尺寸的3倍
resizeOptions.inScaled = TRUE;

选项​​=新DisplayImageOptions.Builder()
.showStubImage(R.drawable.blank)
.showImageForEmptyUri(R.drawable.no_image)
.cacheInMemory()
.cacheOnDisc()
.decodingOptions(resizeOptions)
。建立();
...
 

这code不会使图像由于某种原因,3次小。 也许有人有更好的方法和解决方案如何通过精确指定的密度来调整图像?

谢谢指教!

解决方案

阅读Java文档用心:

  

Options.inSampleSize 进入的选项将不获考虑。根据 imageScaleType(...)选项。

库计算出最合适的样本大小本身

还应考虑 ImageSizeUtil.defineTargetSizeForView(ImageView的ImageView的,INT maxImageWidth,INT maxImageHeight)定义目标大小的图像:

  

大小由目标视图参数,配置参数或设备的显示尺寸定义。   尺寸计算的算法:

     
      
  1. 获取实际绘制的getWidth()的getHeight()视图中。如果认为还尚未领取则转到步骤#2。
  2.   
  3. 获取 layout_width layout_height 。如果两者都没有确切的值,则转到步骤#3。
  4.   
  5. 获取了maxWidth 了maxHeight 。如果两者都没有设置,则转到步骤#4。
  6.   
  7. 获取 maxImageWidth 参数(maxImageWidthForMemoryCache)和 maxImageHeight 参数(maxImageHeightForMemoryCache)。如果两者都没有设置(等于0),然后进入到第5步。
  8.   
  9. 在获取设备的屏幕尺寸。
  10.   

UIL根据 imageScaleType 的targetSize (和的ImageView 的scaleType)。

I successfully applied the Universal Image Loader library (1.8.3 version) to my app and trying to resize the image before displaying it in the gridview item (because sometime image is too big to cache it in memory), here what I am trying:

...
BitmapFactory.Options resizeOptions = new BitmapFactory.Options();
resizeOptions.inSampleSize = 3; // decrease size 3 times
resizeOptions.inScaled = true;

options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.blank)
.showImageForEmptyUri(R.drawable.no_image)
.cacheInMemory()
.cacheOnDisc()
.decodingOptions(resizeOptions)
.build();
...

This code doesn't make image 3 times smaller for some reason. Maybe someone have better way and solution how to resize image by exactly specified density?

Thanks in advice!

解决方案

Read Java docs attentively:

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

Also look into ImageSizeUtil.defineTargetSizeForView(ImageView imageView, int maxImageWidth, int maxImageHeight) which defines target size for image:

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

  1. Get the actual drawn getWidth() and getHeight() of the View. If view haven't drawn yet then go to step #2.
  2. Get layout_width and layout_height. If both of them haven't exact value then go to step #3.
  3. Get maxWidth and maxHeight. If both of them are not set then go to step #4.
  4. Get maxImageWidth param (maxImageWidthForMemoryCache) and maxImageHeight param (maxImageHeightForMemoryCache). If both of them are not set (equal 0) then go to step #5.
  5. Get device screen dimensions.

UIL defines result Bitmap size according to imageScaleType and targetSize (and ImageView's scaleType).

这篇关于Android的通用图像装载机,displaing它在一个视图之前调整图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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