问题
I'm using Picasso
to load images, scale and set to listview
item. There is my code:
Picasso.with(getActivity()).load(builder.toString())
.config(Bitmap.Config.RGB_565)
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
int width = Double.valueOf(bitmap.getWidth() * 0.75).intValue();
int height = bitmap.getHeight();
Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height);
imageView.setImageBitmap(newBitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
The problem appears when I made new Target()
object in the .into()
method, before that the speed of loaded images were very fast.
I thought what exactly slowed down my work and how to correct it? Is scale memory-expensive or this is because of new Target()
implementation at all?
Who faced with this problem? How to solve that?
回答1:
You can use Fresco for image loading..even facebook using same and for scaling you can use android:scaleType.its very usefull Read about Fresco http://frescolib.org/docs/index.html
回答2:
Use the Glide Library An image loading and caching library for Android focused on smooth scrolling.
https://github.com/bumptech/glide
Picasso is also a good for cashing or U can use LRU cache.
回答3:
You aren't seeing slowness. That Target
will probably never be called.
Picasso only holds a WeakReference to a Target
. You need to hold your own reference to that Target
, or else it will be cleared and gc'd before it can be loaded into.
来源:https://stackoverflow.com/questions/35148862/how-to-increase-speed-in-picasso