Gaurav Arora
Gaurav Arora

Reputation: 8362

Image is not auto adjusting

In android, when we open a screenshot from gallery. It comes blurred for 2 secs and then auto adjusts itself.

But when I am using this screenshot image to set on a imageview using image path as :,

Image Path is: /mnt/sdcard/ScreenCapture/SC20130219-124221.png

private void showImage(String imgPath) {
        // TODO Auto-generated method stub

        System.out.println("Image Path is:  "+imgPath);

        ImageView openImage=(ImageView)findViewById(R.id.img_fullScreen);
        ExifInterface exifMedia = null;
        try {
            exifMedia = new ExifInterface(imgPath);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String exifOrint = exifMedia.getAttribute(ExifInterface.TAG_ORIENTATION);
        int exifOrientation = Integer.parseInt(exifOrint);
        System.out.println("Orientation Tag is:"+exifOrientation);
        BitmapFactory.Options mOptions=new BitmapFactory.Options();
        mOptions.inSampleSize=2;
        Bitmap imgBitmap = BitmapFactory.decodeFile(imgPath,mOptions);
        //Runtime.getRuntime().gc();

        imgBitmap = getResizedBitmapImage(imgBitmap, 200, 200, exifOrientation);
        openImage.setImageBitmap(imgBitmap);
    }

Another case: While getting the Bitmap from the URL as :

URL url = new URL(urlTarget);
            BitmapFactory.Options mOptions = new BitmapFactory.Options();
            mOptions.inSampleSize=1;
            Bitmap bmp = BitmapFactory.decodeStream(url
                    .openConnection().getInputStream(),null,mOptions);

Then the image is not auto adjusted itself. It comes BLURRED. THIS IS MY PROBLEM.

IT IS IN THE CASE OF SCREENSHOT ONLY.

tHANKS

Upvotes: 5

Views: 403

Answers (3)

Akhilesh Mani
Akhilesh Mani

Reputation: 3552

Change your code from mOptions.inSampleSize = 2 to mOptions.inSampleSize =1 And your problem will definitely be resolved

Upvotes: 0

s.d
s.d

Reputation: 29436

mOptions.inSampleSize=2; This is going to skip alternate pixel data and load an image 1/2 the original size. Of-course it will look blurred and highly aliased, because this is no where near a good image scaling algorithm.

As far as Gallery app is concerned, it loads progressively, it shows a thumbnail, or a quick render, while full resolution image is being loaded into memory.

Upvotes: 1

Binh Tran
Binh Tran

Reputation: 2488

This is just a tricky behavior of the Android Gallery app (and also is a good example show how to make better user experience if you have to load large images).
At first, when you click on the image thumbnail in the gallery, it will use exactly that thumbnail to display in the ImageView. Because the thumbnail is small and it needs to be scale up to fix the ImageView, you will see it blur.
While displaying the thumbnail to user, it also decoding the original image. When everything's done, the original image will be displayed instead of the thumbnail.
The Gallery also use the animation when switching between the thumbnail and original image (default layout animation you can find it in API Demos)

Upvotes: 0

Related Questions