I am loading images in an ImageView from url. (from RSS feed)
The problem is that the resolution of the loaded image is lower than the original image !!
I searched Stackoverflow and found that the solution is to set the “inScaled” option to false to prevent image re-scaling.
but, this solution didn’t work for me.
Here is the code:
URL feedImage= new URL(img_link);
HttpURLConnection conn= (HttpURLConnection)feedImage.openConnection();
InputStream is = conn.getInputStream();
BitmapFactory.Options BFoptions = new BitmapFactory.Options();
BFoptions.inScaled = false;
Bitmap img = BitmapFactory.decodeStream(is,null, BFoptions);
int density = img.getDensity(); Log.e("img", "Image density is " + density);
int width =img.getWidth(); Log.e("img", "Image width is " + width);
int height = img.getHeight(); Log.e("img", "Image height is " + height);
my_image.setImageBitmap(img);
The variables density, width and height are lower than the original image’s values.
and here is a part of my layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/joke_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="temp description"/>
<ScrollView
android:id="@+id/SV"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:background="@drawable/background"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="50dp">
<!-- bla
bla
bla
-->
</ScrollView>
</RelativeLayout>
Thanks in advance
Finally it was solved 🙂
It appeared to be not related to the code or the ImageViews, …..
All the images in the RSS feeds are thumbnails … which is the reason that they appear small in the app but large in the website.
So the solution was to replace the “_s.jpg” at the end of each image’s url with “_n.jpg” 🙂
I hope this answer will help someone else 🙂