Charl Potgieter
Charl Potgieter

Reputation: 211

URL images are smaller than the original image

I am using xamarin studio. I have to download a bunch of images from a web service. I only get their url and then I use the following code to make the images bitmap

     SetContentView (Resource.Layout.test);
        ImageView img = FindViewById<ImageView> (Resource.Id.image);
        Bitmap bitimage = GetImageBitmapFromUrl ("http://apk.payment24.co.za/promotions/engensa/muffin.png");
        img.SetImageBitmap (bitimage);


   public  static Bitmap GetImageBitmapFromUrl(string url)
    {

        Bitmap imageBitmap = null;
        using (var webClient = new WebClient())
        {


            var imageBytes = webClient.DownloadData(url);
            if (imageBytes != null && imageBytes.Length > 0)
            {
                imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
            }
        }

        return imageBitmap;
    }

The problem is the image I display is very small. If I manually download the images from the url and add it to the project it works perfectly fine. My image view settings are with: match_parent and height: wrap_content. How can I get the original size of the images if I download it via url. Please see this link to see how the image look http://postimg.org/image/c3kbsz903/

Upvotes: 0

Views: 214

Answers (2)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

You need to add android:adjustViewBounds ="true" and android:src="@drawable/ attribute in your Imageview

    <ImageView
   layout_width="match_parent"
   layout_height="wrap_content"
   android:adjustViewBounds ="true"
   android:src="@drawable/ dummy drawable/>

Please Check ScaleType in android .

Upvotes: 2

Neeko
Neeko

Reputation: 1149

You stated that your view attributes are something like this

<ImageView
   layout_width="match_parent"
   layout_height="wrap_content" />

In order to have the original size of the image, you must set the layout_width attribute of your ImageView to wrap_content so that the ImageView won't use its parent's width but will adapt to the image original size.

Upvotes: 0

Related Questions