1

I am using bitmap to get a image from a url using this

public void loadImage(String url){
try {

       bitmap = BitmapFactory.decodeStream((InputStream)new URL(url).getContent());

    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

}

Is there anyway i can resize the image from here? setting the width and the height of it still keeping the resolution?

4 Answers 4

7

Use: Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)

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

Comments

5

You can try this too.

BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1; // 1 = 100% if you write 4 means 1/4 = 25% 
bitmap = BitmapFactory.decodeStream((InputStream)new URL(url).getContent(),
                                                                   null, bmOptions);
bmImage.setImageBitmap(bitmap);

1 Comment

don't you need to pass options anywhere ?
1

You can just use Picasso(very simple!):

Picasso.with(context) .load(url) .resize(10, 10) .into(imageView)

http://square.github.io/picasso/

1 Comment

This worked great for me! was using volley..the whole thing was painful when dealing with images
0

why don't you set the width and height property of imageView in XML?

I find out that the image from url is resized automatically so that it can fit in that imageView.

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.