user1624253
user1624253

Reputation:

Crop the Image and display it

I am getting an image from the Internet and I am showing the image on to the ImageView. Please let me know is there any way in which I can compress the image(to a particular size/dimension) and show it on the Imageview, as the image is user-uploaded image. Thanks

Upvotes: 0

Views: 478

Answers (2)

avepr
avepr

Reputation: 1896

First answer is correct if you need to do it programmatically. However, ImageView also has an option to control how the image shall be cropped or re-scaled. There is an API ImageView.setScaleType(type). If you make the dimensions of your ImageView fixed, then you can control how the image is fit into the area by this method. Please see this link: http://developer.android.com/reference/android/widget/ImageView.html#setScaleType(android.widget.ImageView.ScaleType)

Upvotes: 0

Shrikant Ballal
Shrikant Ballal

Reputation: 7087

You can use BitmapFactory.Options class to crop image to any size.

You can use following:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inSampleSize = 8; // 1/8th of actual image.
BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
String imageType = options.outMimeType;

For more info, please see this.

Upvotes: 1

Related Questions