android - images not showing on device from url - android

I am receiving images from a URL and they display on the emulator but when I use a device the default image is shown. Im not totally sure which part of the code you require so Ill add more on request:
pubImage = extras.getString("pubImage");
ImageView ivimage = (ImageView) findViewById(R.id.image);
try{
ivimage.setImageDrawable(grabImageDrawableFromUrl(pubImage));
Log.d(TAG, pubImage);
}catch(Exception e){
e.printStackTrace();
}

I use Prime for all of my image loading in Android. If you were using it then you would not have to worry about issues like this.

try this...
InputStream is = (InputStream) this.fetch(url);
Drawable d = Drawable.createFromStream(is, "src");
ivimage.setImageDrawable(drawable);
if you still not get solution then use Universal Image Loader

Look at the answer to this question, it seems as if you might be missing a few details, but perhaps you should paste grabImageDrawableFromUrl() either way.

Related

JPG image shows from phone but not from server - android

In my app I am able to pick up a picture from the Gallery and show it on my phone. The picture has extension JPG. But when I email it to myself, save it on the server and then try to display it on my phone, it does not display. I even tried to downsize it to 30% using my email app on the phone, so now it is 220KB instead of 1.4MB but it still does not display.
In both cases I use the method
imageView.setImageBitmap(BitmapFactory.decodeFile(personPicture))
What do I need to do to overcome this problem?
BTW: the name of the picture was changed when I saved it on the server. I do not think it matters but I mentioned it anyway.
EDIT
The above is all the code I am using. Just to complete the issue here is the code that handles both jpg and png and it works if the picture is renamed to png.
if (url.contains("jpg")) {
imageView.setImageBitmap(BitmapFactory.decodeFile(url));
} else {
Drawable drw = LoadImageFromWebOperations(url);
if (drw != null) {
imageView.setImageDrawable(drw);
}
}
Note: the 1.4MB PNG file worked fine on the emulator but gave Out of memory exception on the device. When I re-sized the PNG file to 350KB it displayed properly on the device also.
If needed here is the url used in the above code (a picture of a cat)/
http://212.150.56.58:8080/feedback/pictures/56.png
When you try to load image from server into app, load it using Picasso library like as below:
Picasso.with(MainActivity.this).load("image_to_be_loaded").into(profile_image);
Edit
If you don't want to use third party library then try the following code:
public Drawable loadImageFromURL(String url, String name) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, name);
return d;
} catch (Exception e) {
return null;
}
}
Use Picasso to load server images to your app image view it also supports caching and lot many features.
Use is like this
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
checkout Picasso Library for more details.
I do not understand why, but if I renamed the picture on my server to extension PNG the picture displays, in all sizes.

Dynamically add pictures from Web to ImageView with SimpleAdapter

I have a code similar to this.
And like in there I want to add pictures dynamically to my ListView using a SimpleAdapter, but instead of having the photos on the Drawable resources I want to grab mine from the web. I already have a method that gets a url and returns a Drawable and I want to add the id of that Drawable to the HashMap like he does. How to I get that id (R.drawable.blabla) ?
Btw here's the method
public static Drawable loadImageFromWeb(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
return null;
}
}
Adding a new Drawable Resource at runtime is not possible. Resource ID's and data are generated while editing and bundled into your APK at build time.
Instead create a local cache and load files from there.
Whatever that guy is doing isn't the best way to go about it, use a https://developer.android.com/reference/android/widget/BaseAdapter.html base adapter and override the getview method
Ok, managed to solve the issue with this:
http://www.technotalkative.com/android-asynchronous-image-loading-in-listview/
Very good source, thanks all.

(Beginner) How do I automatically load images off of a website into an imageview

I'm building an app for a friends funny pictures website. I downloaded the gridview activity from the android developers website, but it just loads preset image urls, and that's simply not going to work for us. We need an image loader that can automatically load images from the site.
Any help would be greatly appreciated.
Use lazylist download
https://github.com/thest1/LazyList
Lazy load of images in ListView
Hope AQuery library is what you are looking for easy image loading on ImageView
Try out this
Drawable drawable = LoadImage(<Replace this with your url> + UserProfile.Photo);
UserPhotoImageView.setImageDrawable(drawable);
<replace with Your Image View>.setImageDrawable(drawable);
public Drawable LoadImage(String url)
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}
catch (Exception e)
{
System.out.println("Exc=" + e);
return null;
}
}
Rather than what others are suggesting, I think the best way to do this is use a UniversalImageLoader. It will allow you to Lazy Load, and cache on the SD card and internal storage. In short, it makes things simpler and allows you to get the fastest speed possible. Try it out.

Loading Images From Remote Server?

I have several images on some of my Activities, and these are all connected from Remote Server. The problem is every time I go on one of these Activities that contain images from remote sever. All of the images must load first otherwise you will get a black empty screen. Sometimes it takes about 1-5 minutes to load, and sometimes it even force close the device. Is there anyway I can fix this issue?
Here is the code I'm using:
ImageViewimgView =(ImageView)findViewById(R.id.image01);
Drawable drawable = LoadImageFromWebOperations("http://forum.roda.hr/images/customavatars/avatar10164_2.gif");
imgView.setBackgroundDrawable(drawable);
private Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}
catch (Exception e) {
System.out.println("Exc="+e);
return null;
}
}
I have been struggling for days trying to figure this out, please help me, it would be really mean a lot to me. Thanks in advance!
http://www.androidpeople.com/android-load-image-url-example
this should help..
and as jett try doing it in lazy with AsynTask to do the loading in background..
The key point is that you should use Thread to load the images from Internet.
Please refer to Android - How do I do a lazy load of images in ListView to achieve this.
Better to use thread to download image.
Refer this
Load Image from server using thread
Painless Threading

Android: Getting Drawable from URL not working for .jpg, only works for .png

I am working on and Android app that pulls a picture from an internet page (specifically xckd.com). I have it working wonderfully using code of this basic form (see below)
ImageView iv = new ImageView;
URL url = new URL(address);
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src");
iv.setImageDrawable(d)
I noticed when I was viewing some of their older comics the image would not show (but I was scraping the other information from the page properly so I know the url is correct). I determined that this result only occurs when the image is a .jpg file but works perfectly when it is a .png
I have Googled around plenty and I can't figure out why this is, is there a simple fix for this?
It's a known issue http://code.google.com/p/android/issues/detail?id=6066. Using FlushedInputStream solves it.

Categories

Resources