Glide 4.11 failed to show PNG image with a custom ModelLoader
- Dominant language
- Java
- Stars
- 35k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 8
Description
**Glide Version**: 4.11
**Integration libraries**: No
**Android Version**: 8.1 or later
**Issue details**:
I use Glide to show image with a custom ModelLoader. It worked normally in version 4.10 but when I update to version 4.11 it failed to show over 5MB PNG images in Android 8.1 or later.
**Glide load line / `GlideModule` (if any) / list Adapter code (if any)**:
```java
Glide.with(getContext())
.load(mInputStream)
.listener(mListener)
.into(mView);
```
```java
public class InputStreamModelLoader implements ModelLoader {
@Override
public LoadData buildLoadData(InputStreamModelLoader.Loader model, int width, int height, Options options) {
return new LoadData<>(new ObjectKey(model), new Fetcher(model.load()));
}
@Override
public boolean handles(InputStreamModelLoader.Loader model) {
return true;
}
public interface Loader {
InputStream load();
}
public static class Fetcher implements DataFetcher {
private InputStream mInputStream;
Fetcher(InputStream inputStream) {
mInputStream = inputStream;
}
@Override
public void loadData(Priority priority, DataCallback callback) {
byte[] buffer = new byte[1024];
int read;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
while ((read = mInputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, read);
}
} catch (IOException e) {
}
callback.onDataReady(ByteBuffer.wrap(outputStream.toByteArray()));
}
@Override
public void cleanup() {
}
@Override
public void cancel() {
}
@Override
public Class getDataClass() {
return ByteBuffer.class;
}
@Override
public DataSource getDataSource() {
return DataSource.LOCAL;
}
}
public static class Factory implements ModelLoaderFactory {
@Override
public ModelLoader build(MultiModelLoaderFactory multiFactory) {
return new InputStreamModelLoader();
}
@Override
public void teardown() {
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.