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
Related
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) {
}
};
In my application I'm trying to load image from an https URL using Picasso library.I am unable to load image into ImageView. I am using Picasso 2.5.2 and I am setting the image as follows:
Picasso.with(mContext)
.load(GlobalVariable.movieDetails.get(0).getVideo_cover_image())
.placeholder(R.drawable.animation_placeholder)
.error(R.drawable.animation_placeholder)
.into(iv_image);
Try this
if (TextUtils.isEmpty(imageUrl) && !isValidUrl(imageUrl)) {
iv_image.setImageResource(R.drawable.default);
} else {
Picasso.with(context)
.load(imageUrl)
.resize(70, 70)//if you want resize image
.centerInside()
.into(iv_image, new com.squareup.picasso.Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
iv_image.setImageResource(R.drawable.default);
}
});
}
validate URL
public static boolean isValidUrl(String string) {
boolean b = Patterns.WEB_URL.matcher(string).matches();
return b;
}
Picasso provide a listener for image loading.
Use below code and check image loading status either Success or Error.
Picasso.with(mContext)
.load(GlobalVariable.movieDetails.get(0).getVideo_cover_image())
.placeholder(R.drawable.animation_placeholder)
.error(R.drawable.animation_placeholder)
.into(iv_imagenew,
new com.squareup.picasso.Callback() {
#Override
public void onSuccess() {
//Image Loaded
}
#Override
public void onError() {
//Error while Loading
}
});
please use resize(horizontalSize, verticalSize) method of picaso to resize image. may be your image size is to large thats why it will not load so , please try resize(horizontalSize, verticalSize)
Picasso.with(context)
.load(GlobalVariable.movieDetails.get(0).getVideo_cover_image())
.placeholder(R.drawable.animation_placeholder)
.error(R.drawable.animation_placeholder)
.into(iv_image);
.resize(600, 200) // resizes the image to these dimensions (in pixel). does not respect aspect ratio
.into(imageViewResize);
I have both thumbnail and real images, by now, loading thumbnail first so that user don't have to wait, then after show its real (high quality) image.
But It should not be like this.
Blur to High quality with nice animations.
using Picasso for Image loading.
Thanks to #Vlad Matvienko
Picasso.with(context)
.load(thumb) // thumbnail url goes here
.into(imageView, new Callback() {
#Override
public void onSuccess() {
Picasso.with(context)
.load(url) // image url goes here
.placeholder(imageView.getDrawable())
.into(imageView);
}
#Override
public void onError() {
}
});
This is how it roll.
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 have an image on my server and I want to display it using Picasso on my Android client.
I want to add a default image when the image is loading on Picasso so I am using Target as follows:
Picasso.with(UserActivity.this).load(imageUri.toString()).transform(new RoundedTransformation(500, 1)).into(
new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
userPic.setImageBitmap(bitmap);
}
#Override
public void onBitmapFailed(Drawable drawable) {
userPic.setImageBitmap(defaultDrawable);
}
#Override
public void onPrepareLoad(Drawable drawable) {
userPic.setImageBitmap(defaultDrawable);
}
});
I want to centerCrop() and fit() this image but it gives me an error and it tells me that I cant use them with Target. Is there anyway to use these features on Picasso? Why don't they allow these two functions with Target?
You don't need to use Target to accomplish your goal.
Side note, I am not certain that you can actually use both fit() and centerCrop() together.
See this example:
Picasso.with(context)
.load(url) // Equivalent of what ends up in onBitmapLoaded
.placeholder(R.drawable.user_placeholder) // Equivalent of what ends up in onPrepareLoad
.error(R.drawable.user_placeholder_error) // Equivalent of what ends up in onBitmapFailed
.centerCrop()
.fit()
.into(imageView);
Try this
Picasso.with(context)
.load(url)
.resize(50, 50)
.centerCrop()
.fit()
.placeholder(defaultImageLink)
.error(R.drawable.user_placeholder_error)
.transform(new RoundedTransformation(500, 1))
.into(imageView)
We can also resize the image as required by the imageview which will save memory usage if the image too large.
Callback method can be used to hide the progress bar and show some text within the image View on image load fail.
Picasso.with(context)
.load(url)
.placeholder(R.drawable.placeholder_img)
.error(R.drawable.error_img)
.resize(450, 420)
.centerCrop()
.fit()
.into(imageView, new Callback() {
#Override
public void onSuccess() {
progressBar.setVisibility(View.GONE);
}
#Override
public void onError() {
progressBar.setVisibility(View.GONE);
image_failed_text.setVisibility(View.VISIBLE);
}
});