we are using an app for setting wallpaper in android device, for that we are doing below steps
1) we have set of images and URLs
2) We are fetching the URL on an Imageview
so now we have to set the wallpaper, for that we need the image file, which is the best way to do it?
1) Download the file directly from URL and store it in a local storage and use it as wallpaper.
or
2) Create a bitmap from the Imageview and use it as wallpaper.
Doing the second option will reduce any quality of the image we using?
First option how to we can do it?
We have fetch the images successfully inside the application.
Always prefer to cache your image downloads so that you don't have to repeat the task. Using libraries like Picasso or Glide reduces a lot of effort is handling your images while at the same time optimizing your code.
Additionally it's best to use the original image as wallpaper rather than consuming the image view because if you have set any scale type's on your image view then your image will be cropped.
Picasso allows for hassle-free image loading in your application—often in one line of code!
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
Related
I need to display a list of images in my application, and i get those images from an API call as an URL. Now I'm using Glide to show them, but i don't like the loading effect it makes (blank space while loading, and the the image). Is there any way to instant show those images, without any loading time and possibly without downloading them?
Since the images are stored on a remote server there is no way to bypass the downloading process, however Glide makes sure to only download the image from remote server when necessary, as the docs state
By default, Glide checks multiple layers of caches before starting a
new request for an image:
Active resources - Is this image displayed in another View right now?
Memory cache - Was this image recently loaded and still in memory?
Resource - Has this image been decoded, transformed, and written to
the disk cache before? Data - Was the data this image was obtained
from written to the disk cache before? The first two steps check to
see if the resource is in memory and if so, return the image
immediately. The second two steps check to see if the image is on disk
and return quickly, but asynchronously.
If all four steps fail to find the image, then Glide will go back to
the original source to retrieve the data (the original File, Uri, Url
etc).
To resolve this,
but i don't like the loading effect it makes (blank space while
loading, and the the image)
You can instead add a default placeholder on the ImageView until the real image is downloaded. This will display a default image while your actual image is downloading and then after download completion will replace it with the actual one.
Glide
.with(context)
.load(url)
.placeholder(R.drawable.ic_placeholder) //your default placeholder resource
.into(imageView)
you can display images from url by two ways:
Without any third party library:
URL url = new URL("URL of image here");
Bitmap bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bitmap);
Second way is by using Picasso
I am trying to load images (around 5mb each) into ImageView's of size 45x45 dp in a RecyclerView. Even though original image is large, doesn't Glide load a smaller version of it because target ImageView is small? So, I expect Glide to load images in just a few seconds with an average internet speed. But, it takes like 20 seconds. What is the problem?
Images are stored in firebase storage.
Glide code :
Glide.with(context).load(firebaseStorageUrl).into(imageView);
Glide needs to load the full image from the internet before it can resize it. So the download takes a long time the first time. Afterwards it can use the small image from the cahe it created if you have caching activated.
In case you don't want to load smaller files, I recommend using a Gif-drawable library for loading large images from Glide into GifDrawable(works as an ImageView).
It can load files more than 100MB very fast. It works with plain JPG, PNG and BMP too. If these are GIFs, it plays without any delay or freeze.
If drawables declared by android:src and/or android:background are GIF files then they will be automatically recognized as GifDrawables and animated. If given drawable is not a GIF then mentioned Views work like plain ImageView and ImageButton.
Glide downloads the image first, and then you have methods to retrieve the image as bitmap to resize and compress the image. However, that won't solve your problem . Possibly there are two solutions for this:
Keep a low sized image in the server.
Use a File downloader library, which helps to download images serially and asynchronously as a queue, which would help to download the file quick. FileDownloader library is a good option for this.
Use Override in Glide for load image faster.
I have used both Picasso and Glide in order to load images asyncronously in grids with images coming from the phone's external memory and in order to download photos from the Internet.
But now for my Android game in the first screen I need to display an image below a title (the image takes up all available height). Then the user taps on a specific part of the image and the game starts.
The image content is a drawable resource.
So, for this specific use (a TextView and an ImageView below it which takes up all the remaining space), what should I do:
-Specify the image as ImageView's src property.
-Use an image loading library, such as Picasso or Glide
What do you suggest and why?
Thank you.
EDIT: The image would be static, a static drawable resource.
In my app I have a list view, which contains an image view. The image is loaded from bas64 encoded string. First the string is decoded and then converted it to bitmap and then the bitmap is loaded to the image view.
All the decoding is done in an async task and concurrency is handled according to the below documentation.
Processing Bitmaps Off the UI Thread
The problem is the app is scrolling slow, and all other async tasks are not executing after that.
any possible solutions?
You probably insterting a huge Bitmap into a tiny ImageView like assume the image is FHD 1920x1280 and your ImageView is 192x128. You should load a smaller or same size Bitmap into ImageView. I guess this is a reason of scroll lags. Also it could be that your layout is too complex and should be optimized.
As for
async tasks are not executing after that
nobody can tell you anything without seeing your code.
If you are getting image URL from server you can store if you want to in local DB. Don't store base64 in database just store the image URL's.But for image loading you can simply use libraries that are available like Glide or Picasso for image loading. Your list view is lagging as you are doing heavy operation like decoding base64 and loading that bitmap. Just give it a try, it will work. You can load image using single line code like
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView);
you might need to put images into a folder "drawable-nodpi", since normaly android app will try to resize large image first, then load it, then show show the original image(by resize again), this process will cost much CPU which make your app respond slow. So just create a "drawable-nodpi" folder as the "drawable" folder, cut/paste all large images in the new folder
I want to download some images from the net and show them in an ImageView .So I am using Volley.
How can I reduce the size of the images before showing them in ImageView. The original size of the images are 640 by 640 and I need to use them as an icon. How can I change their size to 64*64.
The question is not related to memory management. I just need to know how can I access the bitmap which I have downloaded from Volley.
The right way:
If you control the server you're requesting images from:
Change the actual image on the server: Create a thumbnail version for your images and use it when appropriate.
If you don't control the server:
Consider creating a service that will do this for you. Something along the lines of:
Ask your image service for an image with a given URL.
Image service checks its cache for a thumbnail version for that URL. If it exists returns it.
Image service retrieves the image, creates a thumbnail version, caches it and returns it to you.
The OK way:
Manipulate the image after it has been downloaded to the device. This isn't optimal but better than nothing. Luckily, Volley provides a built in way to achieve this: simply provide a maxWidth and maxHeight when requesting the image. Something like this (assuming imageLoader is your ImageLoader and imageListener is you listener for this request:
imageLoader.get("http://...", imageListener, maxWidth, maxHeight);
Remember, the full size image will be downloaded to the device with this solution.