I'm using Picasso library in my project to load images. As working with picasso, i thought to show blur image before showing original image. I tried to do it using third party library called "wasabeef transformation" suggested on stackoverflow but couldn't succeed to show blur image before showing original image. This is how i did it.
Picasso.with(context).load(message.body)
.transform(BlurTransformation(context))
.into(photo,object:Callback{
override fun onSuccess() {
Picasso.with(context).load(message.body)
.networkPolicy(NetworkPolicy.OFFLINE)
.into(photo)
}
override fun onError() {
}
})
Edited:
I didn't get any blur image here. It just shows original image after few sec.Also I'm using Recyclerview in my activity and am loading images in my Adapter of Recyclerview. Images are loaded once i get the downloaded image URL. How can i show blur image here with or without any library by Picasso or by any other loading image library. Please tell me .
Create ImageView where you want to load image and blur it. inside your Activity write following code.
Target target = new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
imageViewBackground.setImageBitmap(BlurImage.fastblur(bitmap, 1f,
BLUR_PRECENTAGE));
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
imageViewBackground.setImageResource(R.mipmap.ic_launcher);
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Related
I'm loading smaller quality version of image with Picasso, and if user clicks on that image in a list, then new Activity opens where I'm showing full quality version of image also with Picasso.
Problem is that full quality version of image is large so it takes some time to load it.
I would like that during that period previously loaded smaller quality version of image is shown. Picasso would show it instantly because it was already loaded on previous Activity.
I tried to implement it by call Picasso method twice like this:
Picasso.get().load(url_small_quality).into(imageView)
Picasso.get().load(url_full_quality).into(imageView)
but I think it skips load(url_small_quality) because imageView is empty for some time until url_full_quality is loaded.
I tried to run only load(url_small_quality) and then image is loaded instantly as it should, because it was previously loaded and stored.
Is there a way to somehow set previously loaded smaller quality image as a placeholder until full quality image is loaded?
Most probably picasso is cancelling your previous request , you can try this
Picasso.get().load(url_small_quality).into(imageView,object:Callback{
override fun onSuccess() {
Picasso.get().load(url_full_quality).into(imageView)
}
override fun onError(e: Exception?) {
}
})
You can use a drawable as placeholder but that would be a default image
Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView);
You can load your high quality image after successfully loading your low quality image like below(Since there's no direct way to achieve this or other can be to use disk caching but that would require more efforts) :-
Picasso.with(context)
.load(thumb) // small quality url goes here
.into(imageView, new Callback() {
#Override
public void onSuccess() {
Picasso.with(context)
.load(url) // full quality url goes here
.placeholder(imageView.getDrawable())
.into(imageView);
}
#Override
public void onError() {
}
});
As Astha Garg said in comments this can't be done:
Picasso.get().load(url_small_quality).into(imageView)
Picasso.get().load(url_full_quality).into(imageView)
Simply create one more imageview and place it above previous one with thumb and load your high resolution there.
Java:
Picasso.get().load(url_small_quality).into(IVThumb, new Callback() {
#Override
public void onSuccess() {
Picasso.get().load(url_full_quality).into(IVFull, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError(Exception e) {
}
});
}
#Override
public void onError(Exception e) {
}
});
xml:
inside LinearLayout create:
<ImageView
android:id="#+id/IVThumb"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/IVFull"
android:layout_width="match_parent"
android:layout_height="match_parent" />
I am using Picasso for loading images in image view, and in some condition i load different image but if Picasso failed ti load the new image,it use the error image but i want it to leave the previous image
Example code for your case, if you only need to load an image if the load fails you only need to do the .placeholder part
Picasso.get()
.load(yoururl)
.placeholder(R.drawable.YOURPLACEHOLDER)
.into(yourimgview, new com.squareup.picasso.Callback() {
#Override
public void onSuccess() {
// show img if success
yourimg.setVisibility(View.VISIBLE);
}
#Override
public void onError(Exception e) {
// hide or do nothing on error
imgProducto.setVisibility(View.GONE);
}
});
After I do an image capture intent or gallery pick intent, I receive the selected image. This image I want to resize to certain sizes the selected image and get it as new File in order to send it to server. Is possible to achieve this thing ?? Is there any library that can give you such feature ?
you can use Picasso.
Picasso
.with(context)
.load(UsageExampleListViewAdapter.eatFoodyImages[0])
.resize(600, 200) // resizes the image to these dimensions (in pixel). does not respect aspect ratio
.into(imageViewResize);
and if you want the file after resize you can work with target
.into(new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// send bitmap to server
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});
onBitmapLoaded give you bitmap and this what you need to send to server
I use Picasso library for manage my listview's images. Although images download, they don't appear in imageview immediately. When i scroll page, they appear spontaneously. Relative code snippet:
Picasso.with(context).load(objects.get(position).getUrl()).placeholder(R.mipmap.ins).error(R.mipmap.aramam).into(new Target() {
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Bitmap d = getCircleBitmap(bitmap);
holder.image1.setImageBitmap(d);
}
public void onBitmapFailed(Drawable errorDrawable) {
}
public void onPrepareLoad(Drawable placeHolderDrawable) {
holder.image1.setImageBitmap(getCircleBitmap(BitmapFactory.decodeResource(context.getResources(), R.mipmap.bos_prof)));
}
});
Additional info : When i re-download listview objects , they appear spontaneously too.
Why is this happening??
In picasso problem with Target , with Target they have some issue which you can find here.
I am using Picasso library to load images stored on my server to my android application.
I am using the normal code to do this.
Picasso.with(context)
.load(url)
.resize(50, 50)
.centerCrop()
.into(imageView)
but now i want to set this image as a backgroud to my listview with id = myList .
Any help would be appreciated.
Thank you. :D
You could try to override the new target() implementation to set your view.
Picasso.with(context).load(url).into(new Target() {
#Override public void onSuccess(Bitmap bitmap) {
// Set imageview bitmap here.
// Do other stuff.
}
#Override public void onError() {
}
});
Please take note that the above won't work inside a ListView unless you implement hashCode/equals in your Target.
Implement the Target class.
Pseudo code:
Picasso.with(context).load(...).into(
new Target() {
public void onLoaded(Bitmap bitmap, Picasso.LoadedFrom from){
mListView.setBackground(bitmap);
}
/* ... */
}
);
Note that this code will not compile, as I don't know the exact API's, but this will help you further.