我正在寻找旋转从 Preview Callblack 收到的 YUV 帧预览,到目前为止,我已经创建了这篇文章,其中包含一种旋转帧预览的算法,但弄乱了预览图像相机像素旋转
旋转图像的另一种方法是从 YUV 图像创建 jpg,创建位图,旋转位图并获取位图的字节数组,但我确实需要 YUV (NV21) 格式。
供参考。我问这个问题的原因是因为我有一个支持旋转的相机应用程序,但帧预览仅以横向模式返回。
以下方法可以将 YUV420 字节数组旋转 90 度。
private byte[] rotateYUV420Degree90(byte[] data, int imageWidth, int imageHeight)
{
byte [] yuv = new byte[imageWidth*imageHeight*3/2];
// Rotate the Y luma
int i = 0;
for(int x = 0;x < imageWidth;x++)
{
for(int y = imageHeight-1;y >= 0;y--)
{
yuv[i] = data[y*imageWidth+x];
i++;
}
}
// Rotate the U and V color components
i = imageWidth*imageHeight*3/2-1;
for(int x = imageWidth-1;x > 0;x=x-2)
{
for(int y = 0;y < imageHeight/2;y++)
{
yuv[i] = data[(imageWidth*imageHeight)+(y*imageWidth)+x];
i--;
yuv[i] = data[(imageWidth*imageHeight)+(y*imageWidth)+(x-1)];
i--;
}
}
return yuv;
}
(请注意,只有宽度和高度是 4 倍时,这才可能有效)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)