A very strange behaviour, while writing code for showing GIF image in image-view.
what i am doing is
InputStream is = this.getResources().openRawResource(R.drawable.logo);
logo is gif image that is in the drawable folder.
when I write that line of code in Eclipse , image loads successfully but when I import that code on Android Studio What I am seeing is an error on R.drawable.logo
and the error is
Expected Resource of type raw
supplying the wrong type of resource identifier. For Example when calling Resources.getString(int id), You should be passing R.string.something not R.drawable.something
one code runs on Eclipse not on Android Studio
I am sure that no problem with the imports.
After doing some R&D i have found a work-around for that
and that is instead of creating drawable folder and put that image into it
create assets folder in main/src/assests and paste that image and then open Input steam.
InputStream is = context.getAssets().open("logo.gif");
that worked for me but sill dont know the answer why
InputStream is = this.getResources().openRawResource(R.drawable.logo);
was not working.
you can try using ion https://github.com/koush/ion#load-an-image-into-an-imageview is a nice library for load images and support gif from local store , resorces or from Url.
Simple solution is using Glide library
compile 'com.github.bumptech.glide:glide:4.3.1'
And Load your ImageView
Glide.with(YourActivity.this).load(R.drawable.your_gif).into(yourImageView);
Related
I just install dev-labs-bg /fullscreen-video-view from GitHub and I want to set thumbnail, but the library method use only images from drawable.
val thumbnailResId = R.drawable.video_thumbnail
fullscreenVideoView.videoUrl(videoUrl)
.thumbnail(thumbnailResId)
How I can use image from URL to load into that method.Any clue or this is not postible
It's not supported. I've checked the newest API by myself and can confirm that no method that supports Bitmap or Drawable exists. Here is the snippet from the documentation as a confirmation:
This feature supports loading only drawables from the Android project. Source: https://github.com/dev-labs-bg/fullscreen-video-view#add-thumbnail
I want to load svg image in Android using Glide. In fact Glide support such job and I found a sample https://github.com/bumptech/glide/tree/v3.6.0/samples/svg/src/main/java/com/bumptech/svgsample/app. The question is that I want to directly load the image from a string which is in svg format, not from the svg file. The string is received from network or selected from sqlite. Can someone help me? I have searched a long time but it seems no one meet such requirement.
Your question is unclear. You haven't been that clear on what part you are stuck on.
If you just need to get an InputStream from a String, then you can do:
InputStream stream = new ByteArrayInputStream(svgString.getBytes(StandardCharsets.UTF_8));
I am using holder to set images from Parse to my image view, below is following code
holder.rank.setText(worldpopulationlist.get(position).getRank());
holder.country.setText(worldpopulationlist.get(position).getCountry());
holder.population.setText(worldpopulationlist.get(position).getPopulation());
holder.flag.setImageResource(Integer.parseInt(worldpopulationlist.get(position).getFlag()));
And below is the error given by android studio
java.lang.NumberFormatException: Invalid int: "http://listview123.herokuapp.com/parse/files/hlkhlkhyuiyemnbbmbackguyweuiyqw/10ad83c5546b993c18be84402e0f2bff_android_1.png"
You can't just say "here is the url of the image, do something"
You have to download the image and set is as the wanted resource.
For a guide look here
Or if you want to use an external library you could, like Azmat said, use Picasso
Picasso.with(context).load(imageURL).into(myImageView);
You can use Picasso to load images from link
Picasso.with(context).load(worldpopulationlist.get(position).getFlag()).into(holder.flag);
p.s: this code works if your worldpopulationlist.get(position).getFlag() returns link for file.
I want to image in run time through url in android studio..
For example in eclipse find the image through url in that way..
in that case eclipse has provide that code. I have pass image name in imagename and then get image in drawable.
companyLogo.setImageResource(getResourse.getIdentifier
("com.example.moneymanagement:drawable/"+imagename,null,null));
how to find that case in android studio.. this code has not accepted in android studio. how to find image in run time
try this code:
check the getIdentifier(...) method signature.
String uri="#drawable/" + imageName;
ivImage.setImageResource(getResources().getIdentifier(uri, null, getPackageName()));
Java is Java.. it doesn't matter whether it is compiled by Android Studio or Eclipse. In your case, I think you have getResource.getIdentifier but you should use getResources().getIdentifier(...)
This work Perfect but when you call drawable image then you Conform the package name should be correct. It work Perfect.
companyLogo.setImageResource(getResourse.getIdentifier
("com.example.moneymanagement:drawable/"+imagename,null,null));
I am very new to Android development.
I am trying to add an image to my Android application by code. I found this, but it is showing some drag and drop way to do it.
I want to do it by coding in my onCreate method.
I managed to do this:
ImageView iv = new ImageView(this);
But could not figure out how to set the image-uri.
I tried the following:
iv.setImageURI(#"C:\Users\SONY\Downloads\slide.butcher.home.jpg");
with and without # but I think I need to pass an URI.
I tried to create an object of android.net.Uri, but it seems it can not be instantiated.
See the uri you have tried is wrong it is located on your local file system.. Instead try to push the image on the device's sdcard with the help of DDMS of eclipse..
Suppose you have pushed it on /sdcard/your_image.jpg. then in your code set your image path as
imageView.setImageUri (Uri.parse("/sdcard/your_image.jpg"));
I m sure you will get it...
ImageView iv = (ImageView)findViewById(v);
iv.setImageResource(R.drawable.image);
iv.setImageURI(#"C:\Users\SONY\Downloads\slide.butcher.home.jpg");
You are trying pass Uri of image which is stored on your Computer!!!!
Copy that file on your device SD Card.
Suppose you copied it under /sdcard/home.jpg
Then use below code to display it in ImageView.
imageView.setImageUri(Uri.parse("/sdcard/home.jpg"));