0

I am downloading images from web URL and showing on my android application but I am not able to resize my image according to my requirements.

private Bitmap decodeFile(File f) {
    try {
        //Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        FileInputStream stream1 = new FileInputStream(f);
        BitmapFactory.decodeStream(stream1, null, o);
        stream1.close();

        //Find the correct scale value. It should be the power of 2.

        // Set width/height of recreated image
        final int REQUIRED_SIZE = 285;

        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true) {
            if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE)
                break;
            width_tmp /= 1;
            height_tmp /= 1;
            scale *= 2;
        }
        //decode with current scale values
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        FileInputStream stream2 = new FileInputStream(f);
        Bitmap bitmap = BitmapFactory.decodeStream(stream2, null, o2);
        stream2.close();
        return bitmap;
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;


}

now can any one tell me how can i resize my images to 250*250 px also thanx in advance

1
  • 3
    "i m not able to resize my image according to my requirements" -- please edit your question and explain, in detail, what your problem is. What specifically is not working with the code that you have tried? Commented Jan 6, 2017 at 16:56

1 Answer 1

1

Try and use Picasso library - http://square.github.io/picasso/.

It is fairly easy to use and integrate, and has a resize method doing exactly this.

Picasso.with(context).load(url).resize(250, 250).centerCrop().into(imageView);

you basically put instead of 'url' your url.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.