Android Question Catching errors in LoadBitmap

bryon

Member
Licensed User
Longtime User
What is the proper way to load a bitmap to ensure a corrupted file doesn't kill everything? Is a Try/Catch block acceptable in the release version and what are the consequences of this, if any?

Thanks!
 

Roycefer

Well-Known Member
Licensed User
Longtime User
A Try/Catch will be fine so long as you properly handle the failure to load the bitmap in the Catch block.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that you won't catch the most common error with bitmaps which is OutOfMemory
LoadBitmap / LoadBitmapSample / Bitmap.Initialize / Bitmap.InitializeSample all catch the OOM error internally and downsample the image. The image will be downsampled up to 5 times (1 / 32 of the original size). If at that point the process runs out of memory then it is probably better to let the app crash and fix the issue as there isn't enough memory to do anything useful.
 
Upvote 0
Top