Picasso with recyclerview auto rotates some images - android

I'm having issues with Picasso displaying some pictures in the wrong orientation and others in the right one. I have this one rotated: https://imgur.com/BBSKFJm . I've seen threads like this one: Picasso displays in wrong orientation and this one: Why image auto rotate when set to Imageview with Picasso where it's recommended to either use Compressor from https://github.com/zetbaitsu/Compressor or to manually rotate it.
I was hoping for one that just undoes the weird rotation for a standard recycler view carousel experience pulling from uris. I'd also be open to techniques to keep it uniform such as to crop the images in a recyclerview to deal with the potential issue of the proportions causing this: Android ImageView Displaying Rotated Images Although Source Is Not Rotated.

I faced a problem like this, and I solved it with the Glide library.
dependencies {
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
}
and just
GlideApp.with(context)
.load("http://via.url.com/300.png")
.placeholder(R.drawable.placeholder)
.error(R.drawable.imagenotfound)
.into(ivImg);

Related

Picasso doesn't load view in MainActivity

I'm doing a basic Android Studio Project for loading a URL into an ImageView using Picasso with Kotlin. I have followed every step from the official webpage of Picasso, but when I run my app the emulator shows an empty view.
In my Gradle I added the implementation of Picasso:
implementation 'com.squareup.picasso:picasso:2.71828'
And Internet permission within manifest tag too:
<uses-permission android:name="android.permission.INTERNET"/>
And in MainActivity the basic use of Picasso:
Picasso.get().load("http://paproject.online/hp.jpg").into(imageTest)
imageTest is the id of a Imageview with layout_height = 200dp and layout_weight = 200dp.
Maybe Your Photo size is too big so in ImageView tag in XML Edit layout_width and layout_height to Const Size Like 100dp.
and If U can Change Picasso with Glide. maybe Can help you
Your image is larger (1024x768) than your ImageView, but of course that should not be a reason for you to get blank. Try as below which also includes local image resource nopic for the error cases. Seems you have the correct include
// Lazy load the image with Picasso
get()
.load(yourURL)
.placeholder(R.drawable.nopic)
.error(R.drawable.nopic)
.into(img);
You can resize your image before including it into imageView
Picasso
.with(context)
.load("http://paproject.online/hp.jpg")
.resize(200, 200) // resizes the image to these dimensions.
.into(imageViewResize);
Or you can use any cropping technique like .CenterCrop().
You can read more about this https://futurestud.io/tutorials/picasso-image-resizing-scaling-and-fit
Ok, the problem is already solve. It seems that there is a problem loading images in Android 9.0. So the solution is in this link: Picasso image loading issue with Android 9.0 Pie.
Thanks to everyone for your responses.

Scale an image in Kotlin Android Studio

I'm new to Kotlin and Java and don't know how to scale an image in an image view.
I want something like this: MyImageView.setHeight(300)
I don't want to distort the image.
Thanks in advance!
This solution might be overkill for your current question, but if you have to show images in your app, I recommend using an image handling library such as Picasso or Glide.
If you are to use Picasso, add it to your dependencies by adding the following line to your gradle files :
dependencies {
implementation 'com.squareup.picasso:picasso:2.71828'
}
Then in your Kotlin file, when you are about to load the picture onto an ImageView,
do it using Picasso using the following lines :
Picasso
.get()
.load(imageUrl)
.fit()
.centerInside()
.into(imageView)
Yes, I agree with rgv. Use an image handling library, preferably Picasso. It can reduce a lot of hardwork and also, the result is better than what you would have got by scaling image manually.

Firebase Images are not properly scaling up

I am working on an application which uses Google Firebase and RecyclerView. While retrieving the images from Firebease, images are not properly scaling up. When scrolling the recyclerview, sometimes images are showing as smaller ones and sometimes bigger. They are not scalling properly. I am using Glide to load the images. Please help me .
Also, is it a good idea to use Recuyclerview to use in complex application since OnbindViewHolder being called multiple times causing performance issues. Is there any alternative for that.
Please use this code:
Glide.with(profilePhotoImageView.getContext())
.load(profilePhotoUrl).centerCrop()
.transform(new CircleTransform(profilePhotoImageView.getContext()))
.override(40,40)
.into(profilePhotoImageView);
This means that you are setting a fixed width and height. In which profilePhotoUrl is the url of your image and profilePhotoImageView is the ImageView in which you want to display the image.
And don't forget to add the latest version of Glide in your build.gradle file.
'com.github.bumptech.glide:glide:4.0.0-RC1'
Hope it helps.

Google Photos App style Image Cropping, Straightening and panning

I am looking for Google Photos app style image manipulation. I am kind of new to image processing. Any leads on how to make the cropping rectangle with the image the same size as cropping rectangle, rotation (which rotates both the image and cropping rectangle), image straightening (including how to get that angle slider kind of UI) will be great. If there are some libraries that has these features, that will also work.
Square has a library for loading and playing with images.
Here are some features:
- Handling ImageView recycling and download cancelation in an adapter.
- Complex image transformations with minimal memory use.
- Automatic memory and disk caching.
There is detailed information on how to use the lib on their website. Check it out: Picasso
The gradle line you need to add is:
compile 'com.squareup.picasso:picasso:2.5.2'
It's very easy to use. Here is how I load and adjust an image into an ImageView in my example app:
Picasso.with(mContext).load("http://cdn0.vox-cdn.com/uploads/chorus_asset/file/798874/DSCF1913.0.jpg").fit().centerCrop().into(imageView);
As you can see, I've used fit().centerCrop() here. This will adjust the image to fit proportionally inside my imageView. You can try different forms of image transformations to better fit your needs.
You can also load images from your drawable folder or directly from file:
Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);
Picasso.with(context).load("file:///android_asset/DvpvklR.png").into(imageView2);
Picasso.with(context).load(new File(...)).into(imageView3);
EDIT:
Looks like I didn't fully understand your question when I first read it. Here are some tips for what you're trying to achieve. May not be exactly what you want, but I think it might be a start.
If you want to rotate your image, you can do it with Picasso using RequestCreator.rotate(float degrees).
Here's the documentation for RequestCreator.
As for cropping images (inside a specified rectangle, as you've shown), there is:
Android crop.
Or you can use Picasso Transformations and create a transformation like
CropTransformation(Top, Center, Bottom);
And ask Picasso to transform the image like this:
Picasso.with(mContext).load(R.drawable.demo)
.transform(transformation).into((ImageView) findViewById(R.id.image));
Also, as #Amit K Saha said on his answer, you can use some Android SDK effects. Check android.media.effect.
Hope this helps.
There are some help from android sdk. May not be exactly what you are looking but worth of a shot to start. Have a look here.
android.media.effect
And list of available effects can be found here
http://developer.android.com/reference/android/media/effect/EffectFactory.html

Picasso not loading image for some url

I have an image that I want to download from online.
http://luxproperty.kaytami.com/platform/media/image/jpeg/2014/12/24 Repulse Bay Road.jpg
I have replaced the space with %20, so it becomes
http://luxproperty.kaytami.com/platform/media/image/jpeg/2014/12/24%20Repulse%20Bay%20Road.jpg
The image is not large and so I assume Picasso should be able to load it.
To fit my imageview, I have fit() the image, and the code is as follow:
Picasso.with(mContext).load(UrlEncoder.encode(district.getImage_urls().get(0))).fit().centerCrop().into(holder.image);
However, the image does not appear.
There is a list of 4 items, each containing an image that I load from online. three of them were loaded properly, and the remaining one (http://luxproperty.kaytami.com/platform/media/image/jpeg/2014/12/24%20Repulse%20Bay%20Road.jpg) just does not show up.
Any idea?
I am using Picasso 2.4.0, okhttp-2.1.0 have a look this
It's a bug that is reported to be fixed in the next release of the lib.
You can clone the repo of the lib and compile your own jar or wait.
I recommend you to take a look at Glide. Migrating from Picasso is quite trivial, it has better performance and it makes a nice smooth scrolling on lists.
I had the same problemm when i tried to use Picasso to load images but i used this Library
Its the simplest thing so far by me.
Compile:
compile 'com.koushikdutta.ion:ion:2.+'
Then:
//for activity
ImageView myImage = (ImageView)findViewById(R.id.my_image);
//for fragment
ImageView myImage = (ImageView)rootView.findViewById(R.id.my_image);
Ion.with(myImage)
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.load("http://example.com/image.png");
Hope it helps!!!

Categories

Resources