Rakesh L
Rakesh L

Reputation: 1178

What is the difference between centerCrop and optionalCenterCrop in Glide?

I am building an Android application in which I would like to display images using Glide.

I am able to find the method called centerCrop and optionalCenterCrop as below

Glide.with(imageView.context)
     .load(imageUrl)
     .placeholder(placeHolder)
     .optionalCenterCrop()
     .into(imageView)

I am not able to see any changes in the way the image displayed with the above implementation but the below implementation brings some notable change in the imageView.

Glide.with(imageView.context)
     .load(imageUrl)
     .placeholder(placeHolder)
     .centerCrop()
     .into(imageView)

I would like to understand what is the impact when using optionalCenterCrop() rather than centerCrop()

Upvotes: 1

Views: 418

Answers (1)

Mohammed Junaid
Mohammed Junaid

Reputation: 1412

The difference between optionalCenterCrop() & centerCrop() is that the optionalCenterCrop() applies the centerCrop to all default types and just ignores unknown types while centerCrop() method throws an exception if an unknown Type is used.

Basically the difference is optionalCenterCrop() does not throw Exception on unknown Types while centerCrop() throws an exception which should be handled by you.

Upvotes: 2

Related Questions