I have 4 images set as a background of screens in my application and displaying them cause lags in application. They have 1280x768px and about 70kb. How can I display them without loosing performance?
To use Picasso, simply add this to your gradle:
compile 'com.squareup.picasso:picasso:2.5.2'
And then, in case you have this image on our project folder:
Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);
Instead, if you're downloading the image:
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
Source: http://square.github.io/picasso/
Check google's sample project here: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Related
I'm using Fresco library to show images full screen. How to show animated GIF images full screen using that library? Is there any other optimal solution?
You have to add the dependency for Animated GIF decoding to your Gradle file:
implementation 'com.facebook.fresco:animated-gif:1.12.1'
Then, simply load the image into a SimpleDraweeView:
mSimpleDraweeView.setController(Fresco.newDraweeControllerBuilder()
.setAutoPlayAnimations(true)
.setOldController(simpleDraweeView.getController())
.setUri(yourGifUrl)
.build());
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.
I want to make multiply loading of photos in each cardView at my news feed, like at facebook application.
I found fresco library, but I don't have an algorithm to doing such loading and resizing.
Help me please.
First you need to simply add the following line to the dependencies section of your build.gradle file:
compile 'com.facebook.fresco:fresco:0.12.0'
You use below links for resize:
http://frescolib.org/docs/resizing-rotating.html
https://guides.codepath.com/android/Displaying-Images-with-the-Fresco-Library
Once check for Glide as well
I am using Glide for displaying images in a listview.
How can I use LruBitmapPool to reduce GC (Garbage Collection)?
There is no sample around.
Glide Page :
https://github.com/bumptech/glide
Glide uses the LruBitmapPool automatically so you don't normally need to worry about it. It looks like you posted an issue on Glide's Github page, so let's follow up there: https://github.com/bumptech/glide/issues/326.
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!!!