I had develop an image processor by using YUV420888 in a Xamarin.Forms Android application.
The same code is working on Android 10 Huawei P20, but not on Sonim XP10 Android 12:
var buffer = image.GetPlanes()[0].Buffer;
var bytes = new byte[buffer.Capacity()];
buffer.Get(bytes);
On the Sonim, I got this image instead of clear image :
On the Huawei P20 all is ok :
Can anyone has an idea why on the sonim I got bad image ?
Thank you !
######## Precision :
When I Create my imageReader instance, I use this code :
var map = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
Size[] sizeList = map.GetOutputSizes((int)ImageFormatType.Yuv420888);
foreach (var size in sizeList)
{
if (size.Width == 1280 && size.Height < 1280)
{
idealPhotoSize = size;
break;
}
}
imageReader = ImageReader.NewInstance(idealPhotoSize.Width, idealPhotoSize.Height, ImageFormatType.Yuv420888, 3);
So I ensure that the width is 1280 and for the height, I got 960.
So Width = 1280; Height = 960;
When I receive an image via OnImageAvailable(ImageReader reader) and get image by this code :
image = reader.AcquireLatestImage();
From Sonim, the image indicates the good size of Width 1280 and Height 960 but the buffer is 1 474 304 bytes.
From Huawei P20, the image indicates the good size of Width 1280 and Height 960 with a buffer of 1 228 800 bytes.
So it seems that Android 12/10 or the camera device not working the same way.
Ok,
I resolve my problem. I misunderstood YUV and RowStride.
Because I processed all the bytes array without check RowStride, I cause the behavior.
So I have to read each line by only take the bytes that correspond to the width of the image.
For the P20, the RowStride correspond exactly to the width and in that case, I have to take all the bytes array of the Planes()[0].Buffer
With Sonim, the RowStride is 1536, so I have to parse the bytes array to take only the first 1280 bytes of each line.