Reputation: 3177
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?
Upvotes: 1
Views: 9233
Reputation: 67286
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);
Upvotes: 5
Reputation: 1194
You can just use Picasso(very simple!):
Picasso.with(context) .load(url) .resize(10, 10) .into(imageView)
http://square.github.io/picasso/
Upvotes: 1
Reputation: 273
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.
Upvotes: 0
Reputation: 5099
Use: Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)
Upvotes: 7