admin管理员组文章数量:1315318
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);
}
}
}
}
Share
Improve this question
asked Jan 30 at 9:21
Lala NaibovaLala Naibova
4431 gold badge4 silver badges23 bronze badges
2
- Please edit your question to provide a minimal reproducible example. Make sure everything is there that is needed to actually execute your code while omitting everything that is not essential. – tyg Commented Jan 30 at 10:36
- 1 You might want to look carefully at the coefficients used in your transform to RGB space they don't match the ones that I would expect or those at the Wiki Y'UV page – Martin Brown Commented Jan 30 at 12:27
1 Answer
Reset to default 0I 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);
本文标签: androidHow to avoid blue tint when converting to imageStack Overflow
版权声明:本文标题:android - How to avoid blue tint when converting to image - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741976653a2408162.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论