bumptech / bumptech/glide

Glide centerCrop() not working with CustomTarget ImageView

Open
#4,499 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
35k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
8

Description

**Glide Version**: 4.12.0

**Integration libraries**: N/A

**Device/Android Version**: All

**Issue details / Repro steps / Use case background**:
Run the following code
Observe that the result is actually centerInside not centerCrop
_Actual behaviour_
![glide center crop not working](https://user-images.githubusercontent.com/19919208/109208765-bb794580-7778-11eb-8f71-c47ef13bc716.png)

_Expected behaviour_
![glide center crop expected behaviour](https://user-images.githubusercontent.com/19919208/109208741-b3210a80-7778-11eb-85f1-620551ec723b.png)

**Glide load line / `GlideModule` (if any) / list Adapter code (if any)**:
```kotlin
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

// available in this demo but nullable across my app e.g. in notification or certain screens
val imageView: ImageView? = findViewById(R.id.image)

Glide.with(this)
.asBitmap() // required for image in notification
.load("https://www.lomsnesvet.ca/wp-content/uploads/sites/21/2019/08/Kitten-Blog-1600x2400.jpg")
.centerCrop()
.into(object: CustomTarget() { // again since ImageView not always available, this is the best choice I know of
override fun onResourceReady(resource: Bitmap, transition: Transition?) {
imageView?.setImageBitmap(resource)
// SUCCESS CALLBACK here
}

override fun onLoadCleared(placeholder: Drawable?) {
TODO("Not yet implemented")
}

override fun onLoadFailed(errorDrawable: Drawable?) {
// FAILURE CALLBACK here
}
})
}
}
```
My requirements:

1. ImageView are not always available e.g. notifications. But when the imageView is available, I'd like to use "center crop" instead of "center inside"
2. Callbacks are always necessary

**Layout XML**:
```xml


```

**Stack trace / LogCat**: N/A

![glide centercrop not working](https://user-images.githubusercontent.com/19919208/107121411-404efe80-6860-11eb-880d-354b4ee67ab5.png)

Cross-posting [here
](https://stackoverflow.com/questions/66071616/glide-centercrop-not-working-with-customtarget-imageview)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.