Android Question CameraEx jpgQuality does not change the file size.

TrevT

New Member
Licensed User
Longtime User
I am using the example that is in the cameraEx Zip file. it compiles and runs perfectly on my Samsung S4. The files are about 4MB for a 4128x3096 photo. I would expect that if I edit JpegQuality=10
as shown here then the file size should reduce to about 1/10th the original size.

Sub Camera1_Ready (Success As Boolean)
If Success Then
camEx.JpegQuality=10
'camEx.SetPreviewSize(480,320)
camEx.SetContinuousAutoFocus
camEx.CommitParameters
camEx.StartPreview
Camera_LogFeatures
Else
ToastMessageShow("Cannot open camera.", True)
End If
End Sub


I tried pasting
camEx.JpegQuality=10
camEx.CommitParameters
into many places in the code but the file size is still 4MB
I also set the file name to PNG but no effect.

I tried a few versions of CameraEx such as cameraEx_JB etc but no change in file size.

Any Ideas?
 

TrevT

New Member
Licensed User
Longtime User
OK to answer my own question.

I have done more experiments with this setting and have found that it does reduce the quality but not very well.
A file that has the quality changed from 100 down to 10 takes the file from 800kb down to 140kb. But the quality is very bad. I am trying to make a weather cam and have found many weather cams where the pictures are only 40kb and the picture is quite good.
I have also found that the front camera will produce a much smaller file than the back camera even when both cameras are set on a similar resolution.

So I think I will have to find another library that does a different compression.
Is there another jpeg compression function in B4A or are there more settings available but not implemented in cameraEx?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Did you try to set your Samsung S4 resolution in the camera settings to its lowest possible and then play with the camEx.JpegQuality numbers in your code to see if you can have a good picture quality with lower size.
 
Upvote 0

TrevT

New Member
Licensed User
Longtime User
Did you try to set your Samsung S4 resolution in the camera settings to its lowest possible and then play with the camEx.JpegQuality numbers in your code to see if you can have a good picture quality with lower size.

I tried many settings.
Rear camera at 640x480 and quality at 10 the file was 130kb. This is still a very large file for 640x480.
Also just tried 640x480 on the rear camera with quality at 1, This gave a 110kb file.

It seams a little inconsistent. Yesterday I tried quality of 1 and the picture was terrible it looked like a cartoon but today it is very good quality.

I am setting the quality and comittingParameters just before TakePicture. I assume this is the best place to set it?
 
Upvote 0

TrevT

New Member
Licensed User
Longtime User
Thank you for the help.
I agree, I think the jpeg routine on the camera is holding me back.
It made no difference to compression as to where I changed the setting. It worked the same in camera_ready as in takepicture.
The only thing that reduces the file size is to reduce the image size. The front camera has 320x240 and this does produce a good image with a file size around 30Kb when quality is set to 100. If the quality is set to 10 for the front camera then the picture looks like a cartoon ie about 5 colours and no great reduction in file size.
Maybe if I buy a cheaper phone then the rear camera will have a smaller image size and therefore more compression.
Maybe the compression is built into the hardware and so everything might change with a different phone.

By the way I love how easy the IDE is to use and how the bridge can allow small code changes without a recompile.
The debug interaction is great. Im glad I decided to use B4A it has a good Basic ethos, where a part time hack programmer like myself can get something working within a few hours. My phone can now take pictures while it is asleep and load them to the cloud at the same time.

Just for interest how many professional apps do you think are written with B4A?
 
Upvote 0
Top