Glide Версия: 4.8.0
Библиотеки интеграции: Нет
Версия устройства / Android: OnePlus 3, Android 9.0
Сведения о выпуске / Действия по воспроизведению / Фон варианта использованияЯ использую Glide для загрузки зашифрованных изображений из локального хранилища.Я зашифровал изображения, используя AES-128.Моим первым подходом было декодирование изображения и использование получившегося массива ByteArray для загрузки изображения с использованием Glide.Это хорошо работает для маленьких изображений, но выдает ошибку OOM для больших изображений и когда я пытаюсь загрузить миниатюры видео.Очевидно, этот подход был очень наивным.Затем я создал собственный ModelLoader для загрузки изображения с использованием потока, но они не загружаются.Похоже, проблема в пути декодирования.Я новичок в Glide, и некоторая помощь будет очень ценной.
//one line loader
GlideApp.with(mContext)
.load(CipherInputStream(FileInputStream(File(mPaths.get(p1).mPath)), decCypher))
.thumbnail(0.05f)
.override(size,size)
.transition(DrawableTransitionOptions.withCrossFade())
.apply(RequestOptions().placeholder(R.drawable.image_placeholder).dontTransform())
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(p0.imageView)
//custom ModelLoad
class EncryptedModelLoader : ModelLoader<CipherInputStream, CipherInputStream> {
override fun buildLoadData(model: CipherInputStream, p1: Int, p2: Int, p3: Options): ModelLoader.LoadData<CipherInputStream>? {
return ModelLoader.LoadData(ObjectKey(model.toString()), EncryptedDataFetcher(model))
}
override fun handles(p0: CipherInputStream): Boolean {
return true
}
}
//custom DataFetcher
class EncryptedDataFetcher : DataFetcher<CipherInputStream> {
private var mModel : CipherInputStream
constructor(model : CipherInputStream){
mModel = model
}
override fun loadData(priority: Priority, callback: DataFetcher.DataCallback<in CipherInputStream>) {
var buffer = ByteArray(1024)
callback.onDataReady(mModel)
}
override fun getDataClass(): Class<CipherInputStream> {
return CipherInputStream::class.java
}
override fun cleanup() {
mModel.close()
}
override fun getDataSource(): DataSource {
return DataSource.LOCAL
}
override fun cancel() {
}
}
//custom ModelLoaderFactory
class EncryptedModelLoaderFactory : ModelLoaderFactory<CipherInputStream, CipherInputStream> {
override fun build(p0: MultiModelLoaderFactory): ModelLoader<CipherInputStream, CipherInputStream> {
return EncryptedModelLoader()
}
override fun teardown() {
}
}
//GlideAppModule
@GlideModule
class MAGM : AppGlideModule(){
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
super.registerComponents(context, glide, registry)
registry.prepend(CipherInputStream::class.java, CipherInputStream::class.java, EncryptedModelLoaderFactory())
}
}
Ошибка:
2019-06-15 11:14:26.690 7547-7547/com.example.enead.secretcalculator_001 W/Glide: Load failed for javax.crypto.CipherInputStream@df78e5a with size [14x14]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{CipherInputStream->Object->Drawable}, LOCAL
Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->GifDrawable->Drawable}
Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->Bitmap->Drawable}
Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->BitmapDrawable->Drawable}
2019-06-15 11:14:26.690 7547-7547/com.example.enead.secretcalculator_001 W/Glide: Load failed for javax.crypto.CipherInputStream@df78e5a with size [270x270]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{CipherInputStream->Object->Drawable}, LOCAL
Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->GifDrawable->Drawable}
Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->Bitmap->Drawable}
Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->BitmapDrawable->Drawable}
2019-06-15 11:14:26.692 7547-7547/com.example.enead.secretcalculator_001 W/Glide: Load failed for javax.crypto.CipherInputStream@5903626 with size [270x270]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{CipherInputStream->Object->Drawable}, LOCAL
Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->GifDrawable->Drawable}
Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->Bitmap->Drawable}
Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->BitmapDrawable->Drawable}
2019-06-15 11:14:26.692 7547-7547/com.example.enead.secretcalculator_001 W/Glide: Load failed for javax.crypto.CipherInputStream@8b98eb2 with size [14x14]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{CipherInputStream->Object->Drawable}, LOCAL
Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->GifDrawable->Drawable}
Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->Bitmap->Drawable}
Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->BitmapDrawable->Drawable}
2019-06-15 11:14:26.693 7547-7547/com.example.enead.secretcalculator_001 W/Glide: Load failed for javax.crypto.CipherInputStream@cade3fe with size [14x14]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{CipherInputStream->Object->Drawable}, LOCAL
Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->GifDrawable->Drawable}
Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->Bitmap->Drawable}
Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->BitmapDrawable->Drawable}
2019-06-15 11:14:26.694 7547-7547/com.example.enead.secretcalculator_001 W/Glide: Load failed for javax.crypto.CipherInputStream@cade3fe with size [270x270]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{CipherInputStream->Object->Drawable}, LOCAL
Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->GifDrawable->Drawable}
Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->Bitmap->Drawable}
Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->BitmapDrawable->Drawable}
2019-06-15 11:14:26.694 7547-7547/com.example.enead.secretcalculator_001 W/Glide: Load failed for javax.crypto.CipherInputStream@5903626 with size [14x14]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{CipherInputStream->Object->Drawable}, LOCAL
Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->GifDrawable->Drawable}
Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->Bitmap->Drawable}
Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->BitmapDrawable->Drawable}
2019-06-15 11:14:26.695 7547-7547/com.example.enead.secretcalculator_001 W/Glide: Load failed for javax.crypto.CipherInputStream@8b98eb2 with size [270x270]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{CipherInputStream->Object->Drawable}, LOCAL
Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->GifDrawable->Drawable}
Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->Bitmap->Drawable}
Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{CipherInputStream->BitmapDrawable->Drawable}