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}