Android的通用图像装载机,displaing它在一个视图之前调整图片 [英] Android Universal Image Loader, resize picture before displaing it in a view
问题描述
我成功应用的通用图像装载机库(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)
定义目标大小的图像:
大小由目标视图参数,配置参数或设备的显示尺寸定义。 尺寸计算的算法:
- 获取实际绘制
的getWidth()
和的getHeight()
视图中。如果认为还尚未领取则转到步骤#2。- 获取
layout_width
和layout_height
。如果两者都没有确切的值,则转到步骤#3。- 获取
了maxWidth
和了maxHeight
。如果两者都没有设置,则转到步骤#4。- 获取
maxImageWidth
参数(maxImageWidthForMemoryCache)和maxImageHeight
参数(maxImageHeightForMemoryCache)。如果两者都没有设置(等于0),然后进入到第5步。- 在获取设备的屏幕尺寸。
UIL根据 imageScaleType
和的targetSize
(和的ImageView 定义结果位图的大小code>的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 toimageScaleType(...)
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:
- Get the actual drawn
getWidth()
andgetHeight()
of the View. If view haven't drawn yet then go to step #2.- Get
layout_width
andlayout_height
. If both of them haven't exact value then go to step #3.- Get
maxWidth
andmaxHeight
. If both of them are not set then go to step #4.- Get
maxImageWidth
param (maxImageWidthForMemoryCache) andmaxImageHeight
param (maxImageHeightForMemoryCache). If both of them are not set (equal 0) then go to step #5.- Get device screen dimensions.
UIL defines result Bitmap size according to imageScaleType
and targetSize
(and ImageView
's scaleType).
这篇关于Android的通用图像装载机,displaing它在一个视图之前调整图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!