Bitmaps fail on latest Android OS?

DevBaby

Active Member
Licensed User
Longtime User
My code (whole app in fact) works on various devices (phones, tablet and Kindle fire). However, I just bought a Asus Transformer 10 inch Tablet (latest Android OS) . The same code in my app fails on this device only.

The problem is with loading images and the device fails only on the bold lines below. I don't understand this.

Also, how would I go about getting a log file etc. to find the error message? The app just stops and closes on the lines below. I am using the B4A bridge.





Sub LoadImages

If ImagesLoaded = Null OR ImagesLoaded <> "Load" Then

BmpPage1.InitializeSample(File.DirAssets, "AM_IMG_Page1.jpg",ImgPage1.Width,ImgPage1.Height)
BmpPage2.InitializeSample(File.DirAssets, "AM_IMG_Page2.jpg",ImgPage2.Width,ImgPage2.Height)
BmpPage3.InitializeSample(File.DirAssets, "AM_IMG_Page3.jpg",ImgPage3.Width,ImgPage3.Height)
BmpPage4.InitializeSample(File.DirAssets, "AM_IMG_Page4.jpg",ImgPage4.Width,ImgPage4.Height)

BmpGetLoan.InitializeSample(File.DirAssets, "AM_IMG_Loan.jpg",ImgGetLoan.Width,ImgGetLoan.Height)
BmpPayDebt.InitializeSample(File.DirAssets, "AM_IMG_Loan2.jpg",ImgPayDebt.Width,ImgPayDebt.Height)

BmpSetSail.InitializeSample(File.DirAssets, "AM_IMG_SetSail.jpg",ImgSetSail.Width,ImgSetSail.Height)

BmpBuyGun.InitializeSample(File.DirAssets, "AM_IMG_BuyGun.jpg",ImgBuyGun.Width,ImgBuyGun.Height)
BmpBuyItems.InitializeSample(File.DirAssets, "AM_IMG_BuyItems.jpg",ImgBuyItems.Width,ImgBuyItems.Height)



BmpGameHighLowCoins.InitializeSample(File.DirAssets, "coins3.jpg",ImgGameHighLowCoins.Width,ImgGameHighLowCoins.Height)
BmpGameWarCoins.InitializeSample(File.DirAssets, "coins3.jpg",ImgGameWarCoins.Width,ImgGameWarCoins.Height)

BmpStartUp.InitializeSample(File.DirAssets, "GMP_Splashscreen_T2.jpg",ImgStartUp.Width,ImgStartUp.Height)


If AppOrientation = "P" Then
BmpMapQuest.InitializeSample(File.DirAssets, "AM_IMG_WorldMap.jpg",ImgMapQuest.Width,ImgMapQuest.Height)
End If

BmpPirateBattle.InitializeSample(File.DirAssets, "GMP_Splashscreen.jpg",ImgPirateBattle.Width,ImgPirateBattle.Height)

ImagesLoaded = "Load"

End If



ImgPage1.Bitmap = BmpPage1
ImgPage2.Bitmap = BmpPage2
ImgPage3.Bitmap = BmpPage3
ImgPage4.Bitmap = BmpPage4

ImgGetLoan.Bitmap = BmpGetLoan
ImgPayDebt.Bitmap = BmpPayDebt

ImgSetSail.Bitmap = BmpSetSail

ImgBuyGun.Bitmap = BmpBuyGun
ImgBuyItems.Bitmap = BmpBuyItems

ImgGameHighLowCoins.Bitmap = BmpGameHighLowCoins
ImgGameWarCoins.Bitmap = BmpGameWarCoins

ImgStartUp.Bitmap = BmpStartUp

If AppOrientation = "P" Then
ImgMapQuest.Bitmap = BmpMapQuest
End If

ImgPirateBattle.Bitmap = BmpPirateBattle

End Sub
 
Last edited:

DevBaby

Active Member
Licensed User
Longtime User
After rearranging the order of the image loading sequence above, I see that the device will fail after a certain number of images have been loaded. The lines in bold have nothing to do with the error as they will load if they are the frist two loaded in the sequence.

This appears to be a memory issue somehow. I am doing everything I was advised to do (loading bitmapsample, assigning images to globle variables etc)...it owrks on other devices, but this one fails on the first load.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [ code ] [ /code ] tags (without spaces) when posting code.

Assigning the bitmap to a global variable doesn't save any memory. It is only useful if you use the same image multiple times.

I guess that on the tablet the ImageViews are much larger. This means that the loaded bitmaps will also be larger. A possible solution is to use fixed sizes instead of the view's width and height (for the large images). What will happen is that the image will be slightly stretched. You should test it and see whether it looks fine or not.
 
Upvote 0

DevBaby

Active Member
Licensed User
Longtime User
Thanks Erel,

I resized the pictures, the larger ones slightly smaller than the actual full screen size on the tablet. I had to keep playing with the sizes to get the best possible picture quality. I then saved the files as png as opposed to jpg.

Everything works for "this" Tablet now. I am just not comfortable with the possibility that it may fail on another Tablet. Anyway, thanks for your help.
 
Upvote 0
Top