我正在使用毕加索从URL显示图像,我在加载实际图像之前首先显示缩略图,我想模糊缩略图,我怎样才能在毕加索中实现?
这是我的源代码
pb.setVisibility(View.GONE);
Picasso.with(getApplicationContext())
.load(thumbUrl) // thumbnail url goes here
//.placeholder(R.drawable.progress_animation)
.resize(width, width)
.transform(new BlurTransformation(getApplicationContext(), 25, 1))
.into(imageview, new Callback()
{
@Override
public void onSuccess()
{
pb.setVisibility(View.GONE);
Log.e(TAG,"OnSuccess");
Picasso.with(getApplicationContext())
.load(url) // image url goes here
.resize(width, width)
.placeholder(imageview.getDrawable())
.into(imageview);
iv_reDownload.setVisibility(View.GONE);
}
@Override
public void onError()
{
pb.setVisibility(View.GONE);
Log.e(TAG,"OnError");
Picasso.with(getApplicationContext())
.load(url) // image url goes here
.resize(width, width)
.placeholder(imageview.getDrawable())
.into(imageview);
iv_reDownload.setVisibility(View.VISIBLE);
}
});
答案 0 :(得分:0)
据我所知,毕加索目前并不支持这个"功能"。 Glide库具有非常相似的用途,它具有一个功能,可以轻松使用"快速预览",即低分辨率缩略图,加载速度比全尺寸图像快。
函数为thumbnail(float)
并接受比例因子作为参数,例如0.1f
是原始图像大小的十分之一。
Glide的案例使用可能是这样的。
Glide.with(mFragment)
.load(wFile.getUriForThumb())
.override(length, length)
.thumbnail(.05f)
.placeholder(R.drawable.placeholder_image_128px)
.into(holder.mImageThumb);
方法override
与毕加索的resize(int,int)
相近。
有关两个库之间的完整比较,您可以查看这个很好的指南:Glide vs. Picasso
答案 1 :(得分:0)
最后,我在这个名为picasso-transformations的Library的帮助下解决了我的问题,我在项目中添加了以下依赖项
from collections import defaultdict
# Your input data.
tuples = [(i, i+1) for i in range(1000)]
lists = [[1,2,3,4],[2,3,4,5],[2,3],[4,5,6]] * 1000
def original(tuples, lists):
subsets = {t : set(t) for t in tuples}
mainsets = [set(xs) for xs in lists]
return { tup : sum(s.issubset(m) for m in mainsets) for tup, s in subsets.items() }
def jp(tuples, lists):
subsets = list(map(frozenset, tuples))
mainsets = list(map(set, lists))
d = defaultdict(int)
for item in mainsets:
for sub in subsets:
if sub.issubset(item):
d[sub] += 1
return d
%timeit original(tuples, lists) # 707 ms per loop
%timeit jp(tuples, lists) # 431 ms per loop
不仅支持 Picasso ,还支持 Glide 或 Fresco
我在毕加索里面打了compile 'jp.wasabeef:picasso-transformations:2.2.1'
课。
这里是完整的例子
BlurTransformation
答案 2 :(得分:0)
@Override
public Bitmap transform(Bitmap bitmap) {
// Create another bitmap that will hold the results of the filter.
Bitmap blurredBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
// Allocate memory for Renderscript to work with
Allocation input = Allocation.createFromBitmap(rs, blurredBitmap, Allocation.MipmapControl.MIPMAP_FULL, Allocation.USAGE_SHARED);
Allocation output = Allocation.createTyped(rs, input.getType());
// Load up an instance of the specific script that we want to use.
ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setInput(input);
// Set the blur radius
script.setRadius(10);
// Start the ScriptIntrinisicBlur
script.forEach(output);
// Copy the output to the blurred bitmap
output.copyTo(blurredBitmap);
bitmap.recycle();
return blurredBitmap;
}
答案 3 :(得分:0)
如果您在Picasso中调整图像大小,我已经测试了Glide和Picasso的快速加载,这将提高您的加载速度,这是代码
Glide.with(context)
.load(sArr.get(position).getThumbnail())
.thumbnail(0.01f)
.override(100,100)
.centerCrop()
.placeholder(R.drawable.default_picture)
.into(holder.imgItem);
Piccaso的代码
Picasso.with(context)
.load(sArr.get(position).getThumbnail())
.resize(100,100)
.placeholder(R.drawable.default_picture)
.into(holder.imgItem);
,毕加索获胜!
答案 4 :(得分:-1)
不确定这是否有效但我之前已经看过你可以使用:
.add(new ImageTransform(IMAGE_URL, new BlurTransformation(this)));