Android Question WriteToStream quality

Blueforcer

Well-Known Member
Licensed User
Longtime User
Im generating 8x8 B4Xbitmaps with BitmapCreator.
and save it as jpg and a quality of 100

B4X:
Dim b As B4XBitmap = BitMapList.Get(0)
b.WriteToStream(File.OpenOutput(xui.DefaultFolder, name, False), 100, "JPEG")

While this look very good on iOS (Right) , it look worse on Android (Left):
It looks like the quality parameter has not the same effect as in B4i

1692276708667.png


And no, i cant use PNG :)
 

sirjo66

Well-Known Member
Licensed User
Longtime User
I'm sorry, my mistake, now I have see the problem
Wait....
I trying it.....
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
no solution, I'm sorry
in "frame" list there are only 4 colors, but on the result image there are 8 colors, I don't know why
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I've played with this and I can't see how you obtained that Android image in your first post with the sharply delineated, though incorrect, colour boundaries. Nor do I understand how your iPad can display such sharply defined boundaries on an 8x8 jpg. However.

I'm sure that your jpg is written correctly but an 8 x 8 bitmap has only two vertical pixels for each colour. To see this anything that displays the image at a size visible to a human has to scale up the image. As jpg is a compressive algorithm it throws away the highest spacial frequencies resulting in fuzzy boundaries between colours. The smaller the image the larger the fuzzy boundaries in relation to the size of the image. Because you are always seeing a scaled image what you see is highly dependent on the scaling algorithm used.

I modified your code to produce progressively larger jpg size in multiples of 8 and sure enough, with larger images the apparent colour boundaries get sharper and sharper as expected. I'm afraid that jpg is not a suitable encoding for such small images. I does make me wonder if the iPad does some optimisation when generating or displaying small jpgs that preserves the detail.

I think you have hit a fundamental limit on Android that such small images are not suitable for jpg encoding. As it is icons you appear to need just giving the microcontroller a file with an array of colour values would give correct result as and a much smaller file
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
The images above are shown with html and css with pixelated style.
The microcontroller decodes the image and display it on LEDs. So the user can also just create its own and upload them into the flash memory.

Anyway the app now generates a static GIF instead of a JPG wich works fine and also has also smaller filesize


20230818_195643.jpg
 
Upvote 0
Top