2

I allow user to take photo, and I get this photo to set it in a imageview.

This is my code for my imageview :

        <ImageView 
        android:id="@+id/photo1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"
        android:layout_marginBottom="2dp" />

And my code to put the photo in this imageview :

        imgPhoto1.setImageBitmap(btmap);

My problem is, the photo is showing is blurred.....

How can I do to have a "correct" quality ?

I tried to use this :

getWindow().setFormat(PixelFormat.RGBA_8888);

but it changes nothing.

Thx,

EDIT : Please, I'm searching, if possible, a solution without to use a library, it's just for two imageview..

EDIT 2 : Ok, it seems impossible to do without library, because my image take all of space available on screen.

deveLost
  • 1,151
  • 2
  • 20
  • 47
  • Did you check this link:--http://stackoverflow.com/questions/25071007/imageview-loading-high-resolution-image-as-very-poor-quality. Possible duplicate. – Nicks Sep 12 '14 at 08:32
  • remove `layout_weight` attribute from `ImageView` – Kaushik Sep 12 '14 at 08:41
  • it have nothing to do with library, but if the image is 100x100 pixels and you try to fit in a 1000x1200 View, it will get stretched and "blurred". You have to find yourself a way to better layout that. – Budius Sep 12 '14 at 08:51
  • @Nicks In your case, you seems to use a URI for the image. In my case, i have directly the bitmap. I don't know for the moment how to use this libs correctly :/ – deveLost Sep 12 '14 at 08:51
  • @deveLost : r u accessing that image from `drawable` folder – Kaushik Sep 12 '14 at 08:54
  • The user can take a photo directly on the app, and so I have this photo directly. – deveLost Sep 12 '14 at 08:55

4 Answers4

3

This function resolves the problem of bad quality of a image at ImageView:

public static Bitmap getBitmapFromResources(Resources resources, int resImage) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    options.inDither = false;
    options.inSampleSize = 1;
    options.inScaled = false;
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;

    return BitmapFactory.decodeResource(resources, resImage, options);
}

And imageView.setImageBitmap(getBitmapFromResources(getResources(), R.drawable.image));

Taras Okunev
  • 410
  • 6
  • 9
0

Instead of loading bitmap use universal image loader or picasso for this:

Android-Universal-Image-Loader

picasso

Why use Android Picasso library to download images?

Community
  • 1
  • 1
VINIL SATRASALA
  • 614
  • 5
  • 11
  • mhhh, i don't want to use a lib just for two picture... there isn't something to just have "little" better render ? – deveLost Sep 12 '14 at 08:26
0

You can also use AndroidQuery. It also allows you to load images async. I never had a quality issue with it. It is pretty easy to use and also allows you to cache images.

https://code.google.com/p/android-query/

Warwicky
  • 281
  • 4
  • 9
0

change your imgview width and height style

<ImageView 
        android:id="@+id/photo1"
        <!--android:layout_width="match_parent"-->
        <!--android:layout_height="match_parent"-->
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"
        android:layout_marginBottom="2dp" />

Hope It help

Patato
  • 1,464
  • 10
  • 12
  • Hi, thx for you comm, but I need to have my image take all space on the screen available. – deveLost Sep 12 '14 at 08:53
  • because u use a small size picture displayed in a large view that cause the resize of the img. if you want to keep the image take all space on the screen available then u need a larger size picture – Patato Sep 12 '14 at 09:00
  • I don't think so... the camera of my phone take a photo bigger than my image view. In reality, I've two imageview on my screen. So the size of each imageview, is smaller than my original photo. – deveLost Sep 12 '14 at 09:01
  • it seems the resize of the img causes the problem try this style android:scaleType="fitXY" – Patato Sep 12 '14 at 09:08