I need to convert inputImage to file and upload it. on ios device everything going well, but on android I have blue tint on every my image. my code is like that :
img.Image decodeYUV420SP(InputImage image) {
final width = image.metadata!.size.width.toInt();
final height = image.metadata!.size.height.toInt();
final yuv420sp = image.bytes!;
final frameSize = width * height;
final outImg = img.Image(width: width, height: height, numChannels: 3);
for (int j = 0, yp = 0; j < height; j++) {
int uvp = frameSize + (j >> 1) * width;
int u = 0, v = 0;
for (int i = 0; i < width; i++, yp++) {
int y = (0xff & yuv420sp[yp]) - 16;
if (y < 0) y = 0;
if ((i & 1) == 0) {
v = (0xff & yuv420sp[uvp++]) - 128;
u = (0xff & yuv420sp[uvp++]) - 128;
}
int r = (1.164 * y + 1.596 * v).round();
int g = (1.164 * y - 0.392 * u - 0.813 * v).round();
int b = (1.164 * y + 2.017 * u).round();
r = r.clamp(0, 255);
g = g.clamp(0, 255);
b = b.clamp(0, 255);
outImg.setPixelRgb(i, j, r, g, b);
}
}
}
}
I need to convert inputImage to file and upload it. on ios device everything going well, but on android I have blue tint on every my image. my code is like that :
img.Image decodeYUV420SP(InputImage image) {
final width = image.metadata!.size.width.toInt();
final height = image.metadata!.size.height.toInt();
final yuv420sp = image.bytes!;
final frameSize = width * height;
final outImg = img.Image(width: width, height: height, numChannels: 3);
for (int j = 0, yp = 0; j < height; j++) {
int uvp = frameSize + (j >> 1) * width;
int u = 0, v = 0;
for (int i = 0; i < width; i++, yp++) {
int y = (0xff & yuv420sp[yp]) - 16;
if (y < 0) y = 0;
if ((i & 1) == 0) {
v = (0xff & yuv420sp[uvp++]) - 128;
u = (0xff & yuv420sp[uvp++]) - 128;
}
int r = (1.164 * y + 1.596 * v).round();
int g = (1.164 * y - 0.392 * u - 0.813 * v).round();
int b = (1.164 * y + 2.017 * u).round();
r = r.clamp(0, 255);
g = g.clamp(0, 255);
b = b.clamp(0, 255);
outImg.setPixelRgb(i, j, r, g, b);
}
}
}
}
I have changed jpeg to png and problem solved.
img.Image? decodedImage = decodeYUV420SP(inputImage);
List<int> encodedBytes = img.encodePng(decodedImage);
previous was like that => img.encodeJpg(decodedImage, quality: 100);