Android Question [Solved]Why am I loosing resolution of displayed bitmaps?

opus

Active Member
Licensed User
Longtime User
Hi, I'm drawing bitmaps on a canvas.
The bitmaps are held as properties of objects, I did load them from .Gif-files, held in the Files-Folder, using
B4X:
mBitmap=LoadBitmap(File.DirAssets,"MyGif.gif")
The drawing is done like:
B4X:
mCanvas.DrawBitmap(mBitmap,Null,lRect)

I did get good result, however now I changed the usage in order the use the .Gif-Files as Ressources.
The loading is done like:
B4X:
mBitmapDrawable=Main.MyResources.GetApplicationDrawable("MyGif")
mBitmap=BitmapDrawable1.Bitmap
No change in the drawing code, but now the resolution seems to be lower. At least the displayed Gifs looks "pixolated". The size of the Gif on the screen didn't change!

WHY?
 

DonManfred

Expert
Licensed User
Longtime User
You are running near to OOM so the images will be downscaled.
How big (dimension, not filesize) are the gif?
How ofden do you load it?
Try LoadBitmapSample
 
Upvote 0

opus

Active Member
Licensed User
Longtime User
OOM as OutOfMemory? Why did it work loading the files from File.DirAssests?

I'm loading the files only once.
The gifs are 71*96.

LoadBitmapSample takes a file, like LoadBitmap does. I don't see a way to load the file from the resources?
 
Upvote 0

opus

Active Member
Licensed User
Longtime User
The "lesser resolution" is only for the loaded Gifs, everything else drawn normally.
I do drawn all 104 playing cards, each of them is a .Gif. Using them as a ressource results in this lesser resolution.
If I step back to have them in File.DirAssets I can load them "directly" to a bitmap. Maybe the additional step over a BitmapDrawable is causing this.

Or am I on the wrong track? What is the better suggested way, have the Gifs in File.DirAssets or as Ressources. So far I have onyl one set of cards, even for differnet screen sizes. Any suggestions?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You probably should NOT use a GIF. GIFs are limited to 256 Colors.
Better use PNG or jpg

The best way is probably to use png as drawables in your ressource-folder and load the native drawables.

But maybe it is the amount of images you load. 104 images is a lot. The question is here; are you creating 104 images and load them one by one (dim a bitmapo, noad the image to the bitmap) and then crweating a drawable from this bitmap to add it to a view.
So; are you dimming 104 bitmaps? Or only one which you reuse to load the other 103 images...

Maybe try to create a small project which shows the problem and upload it.
 
Last edited:
Upvote 0

opus

Active Member
Licensed User
Longtime User
Thanks for the help!
The change to .Pngs made a difference.
I did already use the code suggested in the post your are pointing to.

For the number of pictures, I need them all. I'm drawing 2 decks of 52 playing cards for a patience game (in your language called solitaire I presume).
I'm creating a list of card-objects, each of which holds its bitmap as one of the properties.
I added a screenshot.

Thanks for the help again!
 

Attachments

  • Shot3.png
    Shot3.png
    41.2 KB · Views: 199
Upvote 0

wonder

Expert
Licensed User
Longtime User
Canvas is not advisable to any kind of game.
In order of complexity, for your card game, you could use instead one of these libraries:
- GameView
- Accelerated Surface
- LibGDX

Do it so and you won't run into these type of problems again.


Using a different file for each card isn't a good solution as well.
With any of the libs recommended above, you will be able to use a deck of cards spritesheet for your needs.

A simple google search will find you such image, for example:
Deck.png
 
Last edited:
Upvote 0

opus

Active Member
Licensed User
Longtime User
Thanks for this feedback.
I will look into GameView, however using canvas the game is already running as smoth as it was running in VB.Net.
Having ported it to Android I do have a single user now ;-), which is my wife. And she likes it (play-time per week >5 houres!)!
 
Upvote 0

opus

Active Member
Licensed User
Longtime User
Looked into GameView,
IMHO GameView wil help Apps which need to create fast animations.
I my game the user moves the card(s) himself most of the time. That runs smoth!
Only when new cards are placed automaticaly or the desired cards-move is not allowed, an animation is needed.
Using an intervall of 5 and a 2D-distance of 30dip I get fps values of 25 to 30, that seems OK to me.

BTW: When drawing I do it only in the needed part of the canvas, i.e. I .Invalidate only the changed parts!
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
Hello again, @opus!

Yes, indeed for this kind of project, you'll probably do well with Canvas.
The problem begins when what was supposed to be a small project, becomes something bigger.

For example, I know it's not the case, but if you at some point decided to turn your Solitaire card game into a fully fledged Casino app, you would have to restructure your entire code. If one takes the correct approach from the beginning, scalability problems won't arise in the future. I know this seems overkill for a simple Solitaire game, but I just wanted to lend you my advice. I had to restructure my project twice in past and it was a nightmare.

Nevertheless, congratulations on your achievement! Best of success for you! :)
 
Upvote 0
Top