Set ImageView through Uri - android

I am developing Android Web app using restfull web Services.I have written Image in my system as jpg file .Now i need to set Image into ImageView.So I have tried like this
ImageView hotelLogo;
hotelLogo = (ImageView) findViewById(R.id.imgViewHotelLogo);
hotelLogo.setImageURI(Uri.parse("D:/images/Image0800.jpg"));
but it doesn't show image in my ImageView.anyone can correct my code?

Use glide or picaso library to load image from server in both also you can load local image

Related

How to load Image and other content in UI from server

Taking example of viewpager or recyclerview in android we know that they can contain images as well.What i want to know is that how we can load images from database from server and put that images in view pager or recycler view.Upto know my understanding is that i have to make a database in server and put images in it ,now during splash screen download that images and after that put that images into view.Am i going right? Basically what i want to achieve is like shopping app which shows images which changes time to time ? how i can do same ?Do i should go with Rest API to download that images from server and then put in view also do i need to make sure that every time user opens app then it download image?
You can simply fetch .jpg URL from API and then load that image in your app by using Fresco library.
Check this out: Display images with Fresco
First add Fresco to your dependencies in app/build.gradle.
dependencies {
implementation 'com.facebook.fresco:fresco:1.10.0'
}
Don't forget to add in your AndroidManifest.xml proper permission:
<uses-permission android:name="android.permission.INTERNET"/>
Initialize Fresco in class that extend Application class. You can do it in Activity, but it's better to do it just once in Application class.
Fresco.initialize(context);
Instead of ImageView use SimpleDraweeView like this:
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/sdvImage"
android:layout_width="130dp"
android:layout_height="130dp"
fresco:placeholderImage="#drawable/myPlaceholderImage" />
Then just init your SimpleDraweeView object in Activity/ViewHolder/Fragment, parse Url string to Uri like this:
Uri imageUri = Uri.parse("https://i.imgur.com/tGbaZCY.jpg");
And you can set Uri to your SimpelDraweeView object this way:
draweeView.setImageURI(imageUri);
You can use Glide or Picasso as well. Find one that suit your needs by read this post:
Picasso v/s Imageloader v/s Fresco vs Glide

Store images from url in cache and use them as thumbnail or placeholder like whatsapp.

I am developing story feature app like instagram or whatsapp but I got stuck somewhere. I am getting image thumbnail from server as URL but when I try to use it . It take some time to load that image.So I want to Load add thumbnail images from url in previous activity and then set that thumbnail from cache.How I can store url images in cache Hashmap or arraylist to use them in next activity.Please help.I am in trouble right now.
You can use Glide for catching the image from URL.

What is the proper URL to use when loading a gif from Imgur to use in Glide?

I'm looking into using Glide to access gifs off an image hosting website instead of having them all stored in the app within the assets folder. I have Glide working in the sense that it will load the image I specify when the original URL fails.
ImageView imageViewGif = (ImageView) findViewById(R.id.gif);
String gifUrl = "http://imgur.com/gallery/XgbZdeA";
Glide
.with(this)
.load(gifUrl)
.asGif()
.error(R.drawable.alternator_pic)
.into(imageViewGif);
So it loads up alternator pic just fine but I am unable to get it to load an image or gif from the specified URL. What am I missing?

How to load image from SD card using Picasso library

i need to load images from the Sd card into gridview.
For efficiency i'm using Picasso Library
Picasso.with(activity).load(images.get(position).getDataPath())
.resize(96, 96).centerCrop().into(viewHolder.image);
I used the following code in the adapter. unfortunately m unable to see any images
so please can any one help.
Note
And also can anyone suggest any efficient image loading library to load the images from the sd card.
Requirement
I dont to load the image every time when scrolling. If it is already loaded dont load the image on scrolling
To load the file you need to convert it to a uri first
Uri uri = Uri.fromFile(new File(images.get(position).getDataPath()));
Picasso.with(activity).load(uri)
.resize(96, 96).centerCrop().into(viewHolder.image);
Requirement I dont to load the image every time when scrolling. If it
is already loaded dont load the image on scrolling
Picasso is excellent for this
In Picasso version 2.5.2, you need to pass a File as argument to load method, so the image can be loaded as:
Picasso.with(context).load(new File(images.get(position).getDataPath()))
.resize(96, 96).centerCrop().into(viewHolder.image);
I didn't want to create a new File because if the path was already obtained from an existing file, there is no need for a new object (want to see the already existing picture in the device).
According to Picasso docs you have to do something like this:
file:///android_asset/DvpvklR.png
So I used to have:
/storage/sdcard/Pictures/findyoursport/yoursport_1482358052384.jpeg
Prepending: file:// did the trick

Save image to sdcard from imageview

I have listview having customized some textview and one imageview. When I long click on item I have store that item information to the database but the question is how to store image in sdcard and store the relevant path to the database. The image alread download as cache now I don't want to re-download that image.
Is there way to store that Image to the sdcard.
I am using this example to download the images for listview https://github.com/thest1/LazyList
Edit
I got solution
no need to extra process when using this example. Just store the web path of image into the database and pass that imageview into the ImageLoader object with path it'll use the cache images if the image was exist for same URL
No Need to extra process, Using this example it'll will care for future usage also for same URL of image. This will get from the cache directory if the image found that use that image otherwise download it and then use it.
If you use Prime the caching will be transparent, when you request the image again it will grab it from a memory cache if available or a disk cache automatically. It also is really easy to get images with.
You can save your bitmap which you get via Bitmap bitmap=memoryCache.get(url); using save-file-to-sd-card.
You can also get the bitmap from the ImageView(if you want) like:
//say your ImageView object is i;
i = (ImageView) findViewById(R.id.img);
Drawable d = i.getBackground();
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

Categories

Resources