I have an image in my #drawable/myimage.jpg of which I would like to load on my ImageView through Glide. Glide however, only accepts Uri's to load the actual image to the ImageView.
Here's the code:
uriImage = Uri.parse("#drawable/myimage.jpg");
//LOADS IMAGES USING GLIDE
Glide.with(AboutActivity.this).load(uriImage).into(imgView);
It somewhat doesn't work. Is there any work-arounds this?
Sorry for being naive, I just started using Android Studio again :)
try this code:
String imageUrl = getURLForResource(R.drawable.personIcon);
// Load image
Glide.with(patientProfileImageView.getContext())
.load(imageUrl)
.into(patientProfileImageView);
it helps you
Simply do this!
Glide.with(AboutActivity.this).load(R.drawable.resouce_name).into(imgView);
Related
In my application, I was trying to get the thumbnail of a book from google play books API and display it in an image view but somehow what I did is not working.
Glide.with(holder.thumb.getContext())
.load(curThumb)
.into(holder.thumb);
when I used the above method with a local image it worked also thumbnail URL is correct
I tried using Glide v4.0.0-RC1 use RequestOptions to add the placeholder, error image and other options make sure URL(image_url) starts with https, not with HTTP
RequestOptions options = new RequestOptions()
.centerCrop()
.placeholder(R.mipmap.ic_launcher_round)
.error(R.drawable.your_error_image);
RequestOptions to add placeholder, error image and to customize image
Glide.with(this).load(image_url).apply(options).into(imageView);
I'm using Glide to load images in image view from URLs.
If the image is not available in the server and URL doesn't exit/pointing a deleted file then the image view becomes blank..
How to know if URL has a image or not?
//do magic here if/else
Glide
.with(context)
.load(url)
.centerCrop()
.into(myImageView);
Thanks a lot in advance...
Use placeholder() or error() if your objective is to show some local image if the URL does not point to a valid image.
Use RequestListener if you want to learn about failures more generally.
Try out this way.
Glide.with(passContext)
.applyDefaultRequestOptions(
new RequestOptions()
.placeholder(R.drawable.ic_user_default)
.error(R.drawable.ic_user_default)
)
.load(url)
.into(imageview);
So I have an image saved on the external SD-Card. Now, I want to use that image as a resource in my project. (I want to use the image located at the specific path instead of R.drawable.image).
It would be also great, if there was a way to kinda "add" the image to the resources (and not just use it), that the image gets something like a resourceID like the ones in R.drawable got.
But basically I just want to display an external image in an imageView.
First you will need read external storage permission
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
then,
String imagePath = Environment.getExternalStorageDirectory().getAbsolutePath() +"directoryName/imageName.png";
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
ImageView imageView = (ImageView)findViewById(R.id.imageview);
imageView.setImageBitmap(bitmap);
Use the following code.
File file = new File("put your bitmap address here");
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
You cannot add any files to the app package (apk file) in runtime. If you want the image in your drawable folder, you should add it before packaging.
String path = "path-to-image";
Bitmap bitmap = BitmapFactory.decodeFile(path);
Drawable drawable = new BitmapDrawable(bitmap); //if you want a drawable
I use Glide library in my Android project to update avatar from URL that comes in response from API.
The problem is that when I try to load different image (from different URL) to the same imageView it shows me an image that was downloaded first time. (URL forming works fine, I tried it in browser and it shows the needed image)
Here is my code:
EditProfileFragment.xml
public static final String IMAGE_BASE_URL = "http://myapi.com/img/";
String imageUrl = Const.IMAGE_BASE_URL + cb_getProfile.photo; //imageName.jpg
Glide.with(mContext)
.load(imageUrl)
.animate(R.anim.abc_fade_in)
.centerCrop()
.into(mImageView_photo);
Solved this problem by adding a StringSignature when loading image from the URL.
Source
Glide.with(mContext)
.load(imageUrl)
.animate(R.anim.abc_fade_in)
.signature(new StringSignature(String.valueOf(System.currentTimeMillis())))
.centerCrop()
.into(mImageView_photo)
;
Thanks to Yoav Sternberg.
Usually we loading picture is on FragmentPagerAdapter.getItem method.
such as:
Picasso.with(context)
.load(url)
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error).into(imageView);
Images then don't show in ViewPager probably never download. But, I want to pre-download images. I've used Picasso.with().load(url).downloadOnly, but this causes multiple unnecessary same url downloading.
I want to pre-download images. If have same url image downloading, it merge downloading interface.
I'm using Glide.It's effective and power.Preload image only use preload() method.