If I have the URL String such as str_URL = "http://........ABC.png";
How can I add it to below which replace R.drawable.jth?
BitmapDrawable frame1 = (BitmapDrawable)getResources().getDrawable(R.drawable.jth);
BitmapDrawable frame2 = (BitmapDrawable)getResources().getDrawable(R.drawable.jthj);
Android doesn't allow to set an URL as a drawable's source directly, you'll need to write your code to download the file and then use a bitmapfactory to create your drawable.
If you don't want to write code to do that, you can use some open source libraries like Koush's URLImageViewer, if what you want is to display your drawable on an ImageView
Related
I'm making an app that take datas from a database and it should take an ImageIcon. How can I use that class in Android and convert it to Drawable to show it in app?
It's not from a resource file. It's from an ImageIcon as variable of an object i receive from database.
try this
Bitmap bitmap = BitmapFactory.decodeFile("/path/images/image.png");
Drawable d = new BitmapDrawable(getResources(), bitmap);
I'm trying to change a background image on my ViewFlipper... But can't get it to work... Do I have to download the image before set it to the ViewFlipper? .. I saw an example where the URL is used.. But I can't! .
this.vf.setBackgroundDrawable("http://path_to_background_image");
I found the solution myself...
Bitmap bg_img = BitmapFactory.decodeStream((InputStream) new
URL(webservice.getString("background_image_url")).getContent());
vf.setBackgroundDrawable(new BitmapDrawable(bg_img));
I need to retrieve a png image from the Internet. I have the correct URL pointing to the image, it's something like this:
So, I have my URL object like this:
URL url = new URL(methodThatLoadsTheStringPointingToMyURL());
An I can get a InputStream like this:
InputStream is = url.openStream();
However, the only way I know to decode it into a Drawable is by using BitmapDrawable constructor, and that kills the PNG transparency.
Is there any way to retain PNG transparency?
http://www.libpng.org/pub/png/libpng.html
The able link must help you out to address the problem of retaining the Transparency.
Its a standard Library to read and write png image data
I have an image view and a string src. I want to set the imageview source to the string src that I have, but am unable to do so beacuse the method expects an int:
imgview.setImageResource(int);
Since this method takes an int how can I accomplish my goal of using a string?
Each image has a resource-number, which is an integer. Pass this number to "setImageResource" and you should be ok.
Check this link for further information:
http://developer.android.com/guide/topics/resources/accessing-resources.html
e.g.:
imageView.setImageResource(R.drawable.myimage);
To set image cource in imageview you can use any of the following ways. First confirm your image is present in which format.
If you have image in the form of bitmap then use
imageview.setImageBitmap(bm);
If you have image in the form of drawable then use
imageview.setImageDrawable(drawable);
If you have image in your resource example if image is present in drawable folder then use
imageview.setImageResource(R.drawable.image);
If you have path of image then use
imageview.setImageURI(Uri.parse("pathofimage"));
What you are looking for is probably this:
ImageView myImageView;
myImageView = mDialog.findViewById(R.id.image_id);
String src = "imageFileName"
int drawableId = this.getResources().getIdentifier(src, "drawable", context.getPackageName())
popupImageView.setImageResource(drawableId);
Let me know if this was helpful :)
I want to retrieve an image from my data/data/com.apps.myapp/images folder and display it in an ImageView. Any clue?
Try this :
Bitmap bitmap = BitmapFactory.decodeFile("data/data/com.apps.myapp/images/img.png");
ImageView imgView = (ImageView) this.findViewById(R.id.imgViewId);
imgView.setImageBitmap(bitmap);
There are several components involved in this.
To get the path of your data folder you can use the method getDir in the Context.
Now you have to know the file name and open an stream here again the Context class is your friend. Now the stream can be decoded into a Bitmap via a Bitmap Factory.
After you got a Bitmap create a BitmapDrawable from it and pass it to your ImageView