I'm using a 128x128 circular image, animated by a drawable as a placeholder in Picasso.
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/loading_circle"
android:pivotX="50%"
android:pivotY="50%" />
And this is how my Java code implements it:
Picasso.with(context)
.load(message.getMediaUrl())
.config(Bitmap.Config.ARGB_4444)
.resize(w, h)
.onlyScaleDown()
.centerCrop()
.placeholder(R.drawable.progresscircle)
.into(messageImage);
Note that the image sizing parameters above are required by the final image that is loaded into my chat adapter's imageview.
The problem is, Picasso is blowing up and cropping the placeholder like this:
How can I set separate parameters for the placeholder to be suitably sized? Also, what exact parameters would be helpful?
in XML where you set ImageView add.
android:scaleType="centerCrop"
It may work. you can set fitXY instead of centerCrop if it is not working.
As mentioned here,
Inside your imageviews xml set android:scaleType="centerInside"
Then add fit().centerCrop().noFade() like this
Picasso.with(context)
.load(message.getMediaUrl())
.config(Bitmap.Config.ARGB_4444)
.resize(w, h)
.onlyScaleDown()
.centerCrop()
.fit()
.noFade()
.placeholder(R.drawable.progresscircle)
.into(messageImage);
Try this:
Picasso
.with(context)
.load(message.getMediaUrl())
.fit()
// call .centerInside() or .centerCrop() to avoid a stretched image
.into(messageImage);
change your Picasso call to this,
Picasso.with(context)
.load(message.getMediaUrl())
.config(Bitmap.Config.ARGB_4444)
.fit()
.centerCrop()
.placeholder(R.drawable.progresscircle)
.into(messageImage);
Related
I'm using this code to show profile image:
Glide.with(getContext()).load(url)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.circleCrop()
.into(my_profile_image);
But circleCrop() is cropping the image too much. So is there another way to round an image without too much cropping? I research it but I couldn't find another method.
Glide.with(getContext()).load(url)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.apply(RequestOptions.bitmapTransform(new RoundedCorners(10))) // round
.into(my_profile_image);
How about this?
Glide.with(getContext()).load(url)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.apply(RequestOptions.circleCropTransform())
.into(my_profile_image);
I am implementing something called InApp messages, now I am trying to fit ImageView to image size after resizing.
This is my imageView:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="40dp"
android:padding="6dp">
--other components--
<ImageView
android:id="#+id/middleLayoutImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border"
android:padding="5dp"
app:layout_constraintBottom_toTopOf="#+id/middleLayoutText"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/topWrapper"
app:layout_constraintVertical_chainStyle="packed" />
--other components--
</android.support.constraint.ConstraintLayout>
To download img and put into this view I am using Picasso:
Picasso.with(getApplicationContext())
.load(inputurl)
.into(imageView);
Now my activity looks like this:
Before fitting
Now I want to resize it with aspect ratio to width of the parent Layout. I've tried a lot od combinations with no success:
android:scaleType="fitXY" - stretched img
picasso fit().centerCrop() - centerCrop
picasso fit().centerInside() - centerInside
and more combination with android:adjustViewBounds scaleTypes etc.
I want to achieve something like this: Resized correctly - in this case, I've used picasso: .resize(2000,500).centerInside() - but it will work only in this case.. How to do it automatically ?
Thanks in advance for help:)
edit:
ImageView imageView = (ImageView) findViewById(R.id.middleLayoutImage);
String inputurl = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSQtqf1EUqH4eQNNqYFbSawpiR5bypfOhvlatgS0mC3Ve1nk2adbw"; //http://www.gatesms.eu/img/android.png";
Picasso.with(getApplicationContext())
.load(inputurl)
.resize(2000,500)
.centerInside()
.into(imageView);
For Picasso to fit your Image correctly you should know the size of your Image. But for this case You do not know the size of the Image then for good UI design you should have a placeholder (An image to show while Picasso is loading another) keep that image in your drawable folder lets call it placeholder and set it as a src or alternatively using Picasso itself like this:
Picasso.with(getActivity())
.load(imageUrl)
.placeholder(R.drawable.placeholder)
.error(R.drawable.error)
.resize(screenWidth, imageHeight)
.fit()
.centerCrop()
.into(imageView);
Now what?
Now because you have another Image in the imageView Picasso now knows the height and width so that It can fit your Image well. But if you do not provide any image then the results are very small images or improperly stretched ones. I have also added an optional error image that will be displaced if Picasso fails to make the request like my be No network Connection you can omit it if you want.
Do not forget the android:adjustViewBounds in XML too.
I am using Glide frame to load a picture, I want to set the height and the width of it, and I know what is the width I want, but how can I set the height of it.
what I have tried is blow,and I got an error of OOM. waiting for help, thanks.
if you want change size
Glide
.with(context)
.load(UsageExampleListViewAdapter.eatFoodyImages[0])
.override(600, 200) // resizes the image to these dimensions (in pixel). does not respect aspect ratio
.into(imageViewResize);
Reference
Using override method of glide you can set the dimension of image in pixels.
Glide
.with(context)
.load(url)
.override(50 , 50)
.into(imageview);
Is there any way to use xml layout into fresco library instead of hierarchy image?
I used layout like below :
simpledraweeview.getHierarchy().setPlaceholderImage(layout.id);
but it didn't work.
this error hapend :
.Resources$NotFoundException: File res/layout/hierarchy_layout.xml from drawable resource ID #0x7f040049
It means the resource what you are trying to apply is not available. My Suggestion is you can try Picasso library.
Picasso.with(context)
.load(url)
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error)
.into(imageView);
or
you can try Glide library.
Glide.with(myFragment)
.load(url)
.centerCrop()
.placeholder(R.drawable.loading_spinner)
.crossFade()
.into(myImageView);
Fresco supports setting your placeholder in XML: http://frescolib.org/docs/using-drawees-xml.html#_
I've come across this simple problem with the Picasso library. I haven't find any way to put an image into ImageView center it like android:ScaleType="center" does without cropping. Do you have any ideas about how to solve this ? My problem is that I don't know at the runtime the height and width of the BitMap I download so I can't use resize() properly.
This is a little late, but for anyone who's looking for a solution :
Picasso
.with(context)
.load(ImageURL)
.fit()
// call .centerInside() or .centerCrop() to avoid a stretched image
.into(imageViewFit);
If your ImageView is fixed one dimension and flexible another dimension (ex. android:width="match_parent", android:height="wrap_content"), you should be able to use android:adjustViewBounds="true" to get the ImageView to resize to display your image without cropping.
i am not found fit to center without resizing,
Picasso.get()
.load(source).resize(1650,700)
.centerCrop(Gravity.CENTER).into(imageView, new Callback()