Open runInFuture opened 3 years ago
@sjudd any reply is appreciated
I meet this issue too. I guess maybe it is caused by bitmap reuse issue.
Just wanted to add my +1 that this issue exists and makes it hard to optimize an app for low-memory scenarios, given that bitmaps are commonly one of the largest, if not the largest source of memory usage in apps. @sjudd
+1
Highly appreciate if someone can refer to the duplicate links or reference related to this problem
+1
glide version: 4.11.0 integration library: none model: ANA-AN00 os version: EMUI 11.0.0 base on Android 10
Issue details:
When set DecodeFormat to PREFER_RGB_565,glide apply Config.ARGB_8888 to ANY decoded bitmap,even though when a bitmap doesn't has alpha channel. According to the document:
it seems something wrong happed.
Or put another way,how can i make sure glide apply RGB_565 config when decoded a bitmap which has no alpha channel?
The reason why I want to use RGB_565 is for memory consider. RGB_565 use less memory compared to ARGB_8888.
Code
MainActivity
Layout XML
With code list above,issue can be reproduce.
Stack trace / LogCat
As log message show,the final bitmap display by imageView's config is has no alpha channel, config is RGB_565. RGB_565 should 2 byte per pixel,but this bitmap is as big as ARGB_8888 actually.
Analysis
And then i dig in glide's source code,find some point:
Bitmap is decoded by
Downsampler
.Before a real decoded action,Downsampler callgetDimensions
to get bitmap's width and height,and then callcalculateConfig
to fill options.inPreferCofig filed,and then callsetInBitmap
to fill options.inBitmapWhen call
getDimensions
,options.inPreferCofig is nullOptions.outConfig is ARGB_8888 when this method return. This is because of JNI code default behavior.
When call
setInBitmap
expectedConfig is ARGB_8888 assign from options.outConfig. So there whill create a ARGB_8888 bitmap when decode a non-alpha bitmap.
There is my questions
set(Downsampler.DECODE_FORMAT, DecodeFormat.PREFER_xxxx)
does't effect the actual behavior ofDownampler
at all. Is this api totally useless?