In this blog,
I have shown you the how to get the image width and height in Picasso.
Get the width and height
You may get the Bitmap dimensions only after downloading the image. you must use synchronous method call like this:
Synchronous method call like this:
1 2 3 |
final Bitmap myImage = Picasso.with(this).load("YOUR_URL").get(); int width = myImage.getWidth(); int height = myImage.getHeight(); |
This block of code will give the exception, so don’t forget to put this code in try/catch block.
Or
you can use the Target(this is the better way to get the width and height)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Picasso.with(this).load("YOUR_URL").into(new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); imageView.setImageBitmap(bitmap); Log.d("Bitmap Dimensions: ", width + "x" + height); } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }); |