Android Drawable Images from Url

Android Drawable Images from URL

Solved it myself. I loaded it in as a bitmap using the following code.

Bitmap drawable_from_url(String url) throws java.net.MalformedURLException, java.io.IOException {

HttpURLConnection connection = (HttpURLConnection)new URL(url) .openConnection();
connection.setRequestProperty("User-agent","Mozilla/4.0");

connection.connect();
InputStream input = connection.getInputStream();

return BitmapFactory.decodeStream(input);
}

It was also important to add in the user agent, as googlebooks denies access if it is absent

How to Convert Image url into Drawable Int

This code is working for me to convert Server image url into Bitmap

 String drawableRes="http://kartpay.biz/api/v1/file/banner/IHMOcSHU7yoTVOkwYi1bOOz8shrXXrJhayCPFO17.jpeg"
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
URL url = new URL(drawableRes);
headView.setHeadImageBitmap(BitmapFactory.decodeStream((InputStream)url.getContent()));
} catch (IOException e) {
//Log.e(TAG, e.getMessage());
}

how do I transform a string of url's into drawable?

If you have a URL of the picture you need to download it first.

You can't "convert" a URL into a drawable.

you need something like this:

URL url = new URL("http.someimage.com/image.png"); 
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());

Then if you need to add the image into an ImageView object you can call the method .setImageBitmap(bmp).
Otherwise there are ways to extract a Drawable object from the Bitmap
you can check this previous answer. then once you have the drawable you can add it to your arraylist.

Hope I got your question right

P.S.: be sure not to do this on main thread since it is a network operation! use a thread or an asynctask

Convert image URL to drawable resource id in android

You can't convert a Bitmap to a resource id. Resource ids are only for resources in your APK. You'll have to edit or extend the KenBurnsView class to accept Bitmap objects e.g by adding a function like this:

public void setBitmaps(Bitmap... bitmaps) {
for (int i = 0; i < mImageViews.length; i++) {
mImageViews[i].setImageBitmap(bitmaps[i]);
}
}

Then you can pass the Bitmaps that you load with drawable_from_url()

Load image from url


URL url = new URL("http://image10.bizrate-images.com/resize?sq=60&uid=2216744464");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bmp);

How to display image from URL on Android

You can directly show image from web without downloading it. Please check the below function . It will show the images from the web into your image view.

public static Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
return null;
}
}

then set image to imageview using code in your activity.

How to load an ImageView by URL in Android?

Anyway people ask my comment to post it as answer. i am posting.

URL newurl = new URL(photo_url_str); 
mIcon_val = BitmapFactory.decodeStream(newurl.openConnection().getInputStream());
profile_photo.setImageBitmap(mIcon_val);

Android - Reference resource drawable as a URL

Local image resources do not have urls, they have URIs. So if you have image in drawable, you can parse them from resource id to URI.

Uri uri=Uri.parse("R.drawable.image");

However, if you can also put your images in asset folder of the package and access them using their URL. The URL of the image files would be "file:///android_asset/image.png"
You can use either of the option.



Related Topics



Leave a reply



Submit