Fix NPE while making the screenshot bitmap mutable#1005
Fix NPE while making the screenshot bitmap mutable#1005nkming2 wants to merge 1 commit intofarkam135:masterfrom
Conversation
thearaks
left a comment
There was a problem hiding this comment.
The problem can be solved way more easily, see the comments for details.
Thanks for the contribution!
| // Make a mutable copy of the bitmap so we can draw on it with a Canvas | ||
| sCalibrationImage = bitmap.copy(sCalibrationImage.getConfig() ,true); | ||
| sCalibrationImage = bitmap.copy(Bitmap.Config.ARGB_8888 ,true); | ||
| if (sCalibrationImage == null) { |
There was a problem hiding this comment.
This check is useless since the copy can't return a null bitmap.
Please remove this added lines since they're not helpful.
There was a problem hiding this comment.
It could be NULL according to the reference:
If the conversion is not supported, or the allocator fails, then this returns NULL
but yea, I think it's a pretty rare case and maybe just doesn't worth bothering at all
| sCalibrationImage = bitmap; | ||
| } else { | ||
| // Make a mutable copy of the bitmap so we can draw on it with a Canvas | ||
| sCalibrationImage = bitmap.copy(sCalibrationImage.getConfig() ,true); |
There was a problem hiding this comment.
Please replace this line with this instead:
sCalibrationImage = bitmap.copy(bitmap.getConfig(), true);
There was a problem hiding this comment.
That's also what I thought originally but I checked the reference and realized getConfig() could actually return NULL.
If the bitmap's internal config is in one of the public formats, return that config, otherwise return null.
Maybe I just make an if there
| } else { | ||
| // Make a mutable copy of the bitmap so we can draw on it with a Canvas | ||
| sCalibrationImage = bitmap.copy(sCalibrationImage.getConfig() ,true); | ||
| sCalibrationImage = bitmap.copy(Bitmap.Config.ARGB_8888 ,true); |
There was a problem hiding this comment.
Using Bitmap.Config.ARGB_8888 might be a waste of space if the screenshot bitmap used a lower color configuration.
See the previous suggestion to copy the configuration from the screenshot bitmap.
|
Amended |
sCalibrationImage is null at this point, causing NPE when invoking getConfig()
stack trace: