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 :)
 

agraham

Expert
Licensed User
Longtime User
From what I know about JPEG quality that doesn't look like a quality setting issue to me. Quality acts on individual 2D blocks of 8 x 8 pixels and reduces the data saved for each block. The usual effect of low quality is loss of high definition. i.e fuzziness, in both horizontal and vertical directions,. Those images seem to show a consistent actual change in either colour or luminance horizontally exactly half down vertically each colour bar. Moreover it seems to be exhibiting a non-trivial difference in colour values. Can you post a small Android project that shows generating, saving and then displaying the image?
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
I need to build something.
because currently its part of a huge project, the bitmap is generated by a pixeldrawer
1692278164374.png



I also see, that the filesize of android output is 299 bytes, while iOS outputs 822 bytes

A small copy of my current code until i realized a demo, but maybe its also enough?

B4X:
Dim bc As BitmapCreator
bc.Initialize(8,8)
For y = 0 To 7
    For x = 0 To 7
        Dim i As int = y * 8 + x
        Dim a As ARGBColor
        bc.SetARGB(x,y,bc.ColorToARGB(frame.Get(i),a))
    Next
Next
Dim b As B4XBitmap = bc.Bitmap
b.WriteToStream(File.OpenOutput(xui.DefaultFolder, "test.jpg", False), 100, "JPEG")

Also added both jpg here:
iOS:
iOS.jpg
Android:
Android.jpg
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Its just a list of the 64 colors of the pixel grid.
Im saving the 8x8 grid colors into the list, and then getting all the colors agein and generate a 8x8 Bitmap out of it.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I'm missing something here :( Your images imply you want solid colour blocks so why do you need to look up the colour for each pixel up from a list instead pf passing a colour as a parameter. There's too much other code missing to have any idea of what is happening.
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
I dont know what else to explain.

Like you see in my screenshot i have a grid of 8x8 panels, where you can change every panelcolor separately.
Then the user click save, and the generating function runs through all panels, gets the color of it and put it into the frame list.
Then the BitmapCreator takes those colors, and generates a bitmap out of it.

The code for generating the picture with Bitmap-creator works. I know that, because it works in iOS and also for the GIF Encoder on both platforms (also Android). Its just, that WriteToStream doesnt outputs the quality i want, but iOS does (with the exact same code).
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
give us "frame" list, so we can try your code
(ArrayList) [-16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281]
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
ok, but how can I insert it in your code ??

B4X:
Dim frame As List
frame.Initialize
frame.Add ??????
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
B4X:
frame.AddAll(Array As Int (-16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -16449792, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -65536, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -16773889, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281, -65281))
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
your code is ok, all works well, here is the result on test.jpg file
the problem isn't the image, the problem is when the device needs to show on canvas, because the image is very small and so it zoom to fit the space
the result is in screenshot.jpg image
you need create an image more large

P.S.: since the image use only 8 colors, you don't need "frame" list of 64 items
 

Attachments

  • test.jpg
    test.jpg
    9.2 KB · Views: 36
  • Screenshot.jpg
    Screenshot.jpg
    65.3 KB · Views: 42
Last edited:
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
You don't seem to have read my posts in their entirety. I know that the code works.
The problem is also not the zoom because at the end it will not be zoomed. The image size MUST be 8x8.

My problem is that the quality under B4i with the exact same code is much better than under b4a. Also the file size is 3 times bigger with B4i.
And what B4i outputs is what i also need in b4a

Both are 8x8 pixel

1692285862602.png
 
Last edited:
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
it's very strange that you show on canvas an image 8x8 pixels size.
I tried it on my phone, (1080x2280 pixel - 5.8") and I can't see the image.
Wait, I get my glasses......
No, the image 8x8 is very very small, I don't see if it is blured or not, how can you see it ?
the image in your first post is 145x145, so you have zoomed it
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
it's very strange that you show on canvas an image 8x8 pixels size.
I tried it on my phone, (1080x2280 pixel - 5.8") and I can't see the image.
Wait, I get my glasses......
No, the image 8x8 is very very small, I don't see if it is blured or not, how can you see it ?

Its not made for displaying on a canvas it will be saved on a microcontroller and then decoded for a 8x8 RGB LED matrix.

And if i want to display it, i can do it easily with CSS. but thats not the point of this discussion i think

photo_5399940778307997481_y.jpg
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
You wrote: "It looks like the quality parameter has not the same effect"
The answer is: no, it is not a problem of quality parameter, it works !!

Ok... i will shorten my Question again:
In B4i (Apple), the generated JPG file has much better quality than in B4A (Android). Why? And how to get the same quality in B4A
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
and the ask is the same: how do you watch the image on Android ??
Bro, i already answered.. But this question its still totally out of topic.
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
I'm very sorry that I can't help you.
If you read well what Agraham wrote, you can understand what I mean

From what I know about JPEG quality that doesn't look like a quality setting issue to me.
...
Can you post a small Android project that shows generating, saving and then displaying the image ?
 
Last edited:
Upvote 0
Top