-2

I'm downloading an image from a URL and displaying it in an ImageView. I need to download the image at its full original size. I've tried Glide, Picasso and Universal Image Loader with no success. Is there any library or mehod out there to achieve this? I even tried making my own AsyncTask to do it, something like this:

public class ImageLoader extends AsyncTask<Void, Void, Bitmap> {

    @Override
    protected Bitmap doInBackground(Void... params) {

        try {
            URL url = new URL(bundle.getString("selectedImage"));
            HttpURLConnection conn = 
            (HttpURLConnection)url.openConnection();
            conn.setReadTimeout(6000);
            conn.setConnectTimeout(6000);
            conn.setRequestMethod("GET");
            conn.setDoInput(true);
            conn.connect();
            int respose = conn.getResponseCode();
            InputStream is = conn.getInputStream();
            BufferedInputStream bufferedInputStream = new 
            BufferedInputStream(is);
            bitmap = BitmapFactory.decodeStream(bufferedInputStream);

            return bitmap;

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

but no success. Anyone have anything to help me?

TWiStErRob
  • 44,762
  • 26
  • 170
  • 254
Martin Seal
  • 616
  • 2
  • 14
  • 32
  • 1
    How do you know that image is not being downloaded in full size? Maybe it is being downloaded okay but it is cropped when you try to display it? – Ivan Aug 11 '15 at 19:34
  • We do not know what is exactly the issue ! – Anthony May 31 '16 at 17:10

3 Answers3

0

1) Try to use Volley library. https://developer.android.com/training/volley/request.html#request-image

2) Use WebView instead ImageView

dieter_h
  • 2,707
  • 1
  • 13
  • 19
0

I'm not really sure what you mean by "its full original size". I haven't experienced any automagic scaling of images simply by downloading them.

Maybe you could double-check that you have an appropriate android:scaleType on the target ImageView. You can read more on the different values of the scale type property here: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

If you want to pan the image, like an "unscaled" web page in the browser (typically when the image is bigger than the screen), you might need to add further logic to manage this. Maybe it could be as easy as having a ScrollView wrap your ImageView (which then would wrap its content, of course).

dbm
  • 10,376
  • 6
  • 44
  • 56
  • thank you for your feedback my image view is wrapped in a horizontal scroll view which is wrapped in a scroll view, (or visa versa, I forget) but I'm getting the image from the URL which in some cases are as big as 1900 x 1500 the image is definitely not its full size and barely fills half the image view and using my save function it saves the image and on checking the file size it is at around half of the original at around 1024x1024 or 1024x910 depending on the image as they are all slightly different in size – Martin Seal Aug 11 '15 at 21:58
  • 1
    Maybe the hosting server has some logic detecting your client as a mobile device and, hence, serving a smaller image. Maybe you could try to download the same image from the mobile browser and verify the downloaded size. If the server is auto-nice to you, then there isn't much to do, I'm afraid. Maybe playing with some header flags or cookies... – dbm Aug 11 '15 at 22:17
  • I've just checked it quite extensively using the same links and it seems to be just fine with giving me the correct size image but maybe it's not behind the scenes, I'm using photo bucket, (full of ads) I'll search for something better – Martin Seal Aug 11 '15 at 22:27
  • I see. Unfortunately I think I've exhausted all my ideas for now. I hope you find an answer to your issue soon :-) – dbm Aug 11 '15 at 22:37
  • you've been great thank you I will try flikr in the morning and update thus post – Martin Seal Aug 11 '15 at 22:41
  • Tried flikr and its working pulling the image in at its full size if you want to add this as the answer I'll accept it, thanks again @dbm – Martin Seal Aug 12 '15 at 10:44
  • 1
    Great! Always cool when an issue is solved in a timely manner :-) I'll leave the formalities of creating and accepting the answer to you. I don't feel I contributed more than suggesting non-working solutions. And besides, you have the particular details on how-and-what you did to solve the issue. – dbm Aug 12 '15 at 11:08
0

The error was down to photo bucket giving me a scaled down URL instead I used flikr and on my device I get an image almost identical to my original (Picasso limit is 2048x2048) but on other devices I still seem to get a 1080 x 910 image, will investigate further but it seems the answer is not to use photo bucket

Martin Seal
  • 616
  • 2
  • 14
  • 32