How to use setImageURI() in android? - android

I tried
imageView=(ImageView)view.findViewById(R.id.imageView);
Uri photoUrl = profile1.getPhotoUrl();
imageView.setImageURI(photoUrl);
But i dont see anything.
I am getting url when i am printing it
Thanks in advance

Try to use picasso for this:
Picasso.with(context)
.load(url)
.placeholder(R.drawable.placeholder)
.resize(imgWidth, imgHeight)
.centerCrop()
.into(image);

Try this
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("YOUR_URL").getContent());
imageView.setImageBitmap(bitmap);

Related

How to Load tinyUrl in glide?

I'm trying to load the tinyUrl into an ImageView using Glide. below is the mentioned URL.
String imageUrl = "http://hck.re/3Cm0IX";
Glide.with(context)
.load(imageUrl)
.into(imageView);
apparently this isn't working.
Try to change your imageUrl with the following :
String imageUrl = "https://s3-ap-southeast-1.amazonaws.com/he-public-data/aik_alif4181734.jpg" ;
I was able to solve it using the below URL
https://mindorks.com/android/store/Image-Loaders/aminography/redirectglide

Show .gif from Firebase Storage link

I have link in my Firebase Storage on .gif file
String gifUrl = "https://firebasestorage.googleapis.com/v0/b/rokitskiydev-a18ca.appspot.com/o/WF%2F10-16-02-Digital-15.gif?alt=media&token=0354f6e6-4292-4911-9302-49281d293a80";
I try use Picasso and Glide. But I can show only image of this gif.
GlideApp.with(context).load(gifUrl).into(ImageView);
If i get another link, an example http://i.imgur.com/1ALnB2s.gif it's OK!
How can I do this?
Get the downloadUrl of the gif and then use that to load the gif with Glide.
ImageView imageView = (ImageView) findViewById(R.id.imageView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(downloadUrl).into(imageViewTarget);
For newer versions of Glide try this:
Glide.with(context)
.load(imageUrl)
.asGif()
.placeholder(R.drawable.loading2)
.crossFade()
.into(imageView);
As Glide Documentation says,
You can use .asGif() to force the library to load an animated gif and fail if it is not :
Glide.with(activity).load(gifUrl).asGif().into(view);
try this
Check the doc: https://futurestud.io/tutorials/glide-displaying-gifs-and-videos
also as FirebaseDoc says you can do this to load an image/gif with glide
first declare this in your build.gradle
dependencies {
// FirebaseUI Storage only
compile 'com.firebaseui:firebase-ui-storage:0.6.0'
}
then
this to load your image with firebase
// Reference to an image file in Firebase Storage
StorageReference storageReference = ...;
// ImageView in your Activity
ImageView imageView = ...;
// Load the image using Glide
Glide.with(this /* context */)
.using(new FirebaseImageLoader())
.load(storageReference)
.into(imageView);
if you need the url of your image/gif file, you can do this
storageRef.child("your/firebase/imagepath.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png'
Uri downloadUri = taskSnapshot.getMetadata().getDownloadUrl();
generatedFilePath = downloadUri.toString(); /// The string(file link) that you need
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception exception) {
// Handle any errors
}
});

Android - How to Load Image by name using Glide

Hi I'm using Glide to load image from my drawable folder and all works fine, this is my code :
Glide.with(this).load(R.drawable.my_drawable_image_name).into(myImageView);
I'm wondering if there is a way to load the image just by name, something like :
Glide.with(this).load(my_drawable_image_name).into(myImageView);
because i want to get the image name dynamically ,for example from a database...
do you have any suggestion about that?
thanks in advance.
Call getImage method for get Drawable using Name only.
Glide.with(this).load(getImage(my_drawable_image_name)).into(myImageView);
public int getImage(String imageName) {
int drawableResourceId = this.getResources().getIdentifier(imageName, "drawable", this.getPackageName());
return drawableResourceId;
}
Try this:
Glide.with(this)
.load(getResources()
.getIdentifier("my_drawable_image_name", "drawable", this.getPackageName())
.into(myImageView);
Use Uri.
String image = "image.jpg";
String completePath = Environment.getExternalStorageDirectory() + "/" + image;
File file = new File(completePath);
Uri uri = Uri.fromFile(file);
Glide.with(this).load(uri).into(imageView);
You can use the following code to get Bitmap, Drawable from URL using Glide. This code snippet is used to set drawableEnd/drawbleRight for TextView.
Glide.with(context)
.asBitmap()
.load(url)
.into(object : CustomTarget<Bitmap>() {
override fun onResourceReady(
bitmap: Bitmap,
transition: Transition<in Bitmap>?
) {
val drawable: Drawable = BitmapDrawable(
context.resources,
bitmap
)
textView.setCompoundDrawablesWithIntrinsicBounds(
null, null, drawable, null
)
}
override fun onLoadCleared(placeholder: Drawable?) {
}
})
I think you should try this
Glide.with(mContext)
.load(mContext.getResources().getDrawable(R.drawable.my_drawable_image_name))
.placeholder(R.mipmap.icon)
.into(myImageView);
Load method of Glide also accept drawable object as a parameter to load image. You just have to get the drawable object from your drawable image and pass it to the load method.
I wanted rounded-corner of image and that's why I used Glide. In your case, You should use this.
myImageView.setImageDrawable(mContext.getResources().getDrawable(R.drawable.my_drawable_image_name))
If you also want rounded image use this.
Glide.with(mContext)
.load(Glide.with(mContext)
.transform(new FitCenter(), new RoundedCorners((int) mContext.getResources().getDimension(R.dimen._10sdp))
.placeholder(R.mipmap.icon)
.into(myImageView);
Easy way to load image from drawable by using Name
Glide.with(context)
.load(context.getResources().getIdentifier("my_drawable_image_name", "drawable", context.getPackageName()))
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.placeholder(R.drawable.add_photo_placeholder)
.error(R.color.red)
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.into(userPhoto);

How to set image file to ImageView or NetworkImageView using Volley in Android?

I have one API,it will give an image as response.Can you suggest me how can set that image to ImageView.Thanks,
`
private static final String URL = "http://someapi";
setting images from api
person.setThumbnailUrl(Picasso.with(getApplicationContext()).load((File) items.get("profileImageLargeUrl")));
This is the way you can set a picture from URL ussing Picasso (you don't need Volley):
ImageView picture = (ImageView) findViewById(R.id.my_image);
String urlImage = "https://...";
...
Picasso.with(this)
.load(urlImage)
.into(picture);
Also you can set other options, like spiner, fit, or errorImage:
.placeholder( R.drawable.progress_animation )
.error(R.drawable.error_image)
.fit()

Set image on imageview from url resources

I have image with url.
How can I assign this resource to an imageview inside my app?
Check this Picasso library and it very easy to load image url on imageview
http://square.github.io/picasso/
Picasso.with(context)
.load(url)
.resize(50, 50)
.centerCrop()
.into(imageView)
Try this :
URL url = new URL("http://yourURL.com/...");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bmp);
you must use picasso,
for example
Add this line in build.gradle
compile 'com.squareup.picasso:picasso:2.5.2'
and you code :
ImageView horario = (ImageView)findViewById(R.id.imageView4);
Picasso.with(this).load("http://i.imgur.com/DvpvklR.png").into(horario);
Documentation

Categories

Resources