Picasso doesn't load view in MainActivity - android

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.

Related

How can I load image on Picasso?

How can I load image on android studio by using Picasso libary. I tried it before but no image shown...
Note: Libary implementation, Internet access permission everything I do correctly but nothing happened...
Below is the example to load the image with Picasso.
Picasso.with(mcontext).load(URLDecoder.decode(current.getImage(), "UTF-8"))
.placeholder(R.drawable.program)
.into(holder.imageView);
Share your code here so we can check.

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.

loading image into android imageView with ion returns a blurry result

I'm trying to load an image from filesystem into an imageView with the ion library.
When I'm using the following code:
Ion.with(imageView)
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.load(uri);
it (sometimes) results in a kind of blurry image.
When not using ion like the following the pictures appear sharply:
imageView.setImageBitmap(BitmapFactory.decodeFile(uri.toString()));
Is there a standard compression coming with ion that I can disable?
Strangely not every picture is blurry when using ion, e.g. I have two identical images, only with another name. When I load them into the imageView with ion one is blurry, one is not.
Any help or tips are appreciated!
Ion tries to load the image to fit the bounds of the ImageView. So make sure your ImageView is sized properly in your layout. Alternatively, if you use adjustViewBounds=true to indicate the ImageView is adjusted by the image contents, it won't do that. Or alternatively smartsize(false).
Try this,
Ion.with(context)
.load(url)
.withBitmap()
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.intoImageView(imageView);

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