仅供参考.我问这个的原因是因为我有一个支持旋转的相机应用程序,但帧预览仅在横向模式下返回.解决方案以下方法可以将一个YUV420字节数组旋转90度.private byte[] rotateYUV420Degree90(byte[] data, int imageWidth, int imageHeight){字节[] yuv = 新字节[图像宽度*图像高度*3/2];//旋转 Y 亮度int i = 0;for(int x = 0;x < imageWidth;x++){for(int y = imageHeight-1;y >= 0;y--){yuv[i] = 数据[y*imageWidth+x];我++;}}//旋转 U 和 V 颜色分量i = 图像宽度*图像高度*3/2-1;for(int x = imageWidth-1;x > 0;x=x-2){for(int y = 0;y < imageHeight/2;y++){yuv[i] = 数据[(图像宽度*图像高度)+(y*图像宽度)+x];一世 - ;yuv[i] = 数据[(图像宽度*图像高度)+(y*图像宽度)+(x-1)];一世 - ;}}返回 yuv;}(请注意,这可能仅在宽度和高度为 4 的因数时才有效)I'm looking to rotate a YUV frame preview recieved from a Preview Callblack, so far I've founded this post which cointains an algorithm to rotate the frame preview but is messing the preview image camera pixels rotatedanother way to rotate the image will be creating a jpg out of the YUV image, create a bitmap, rotate a bitmap and obtaining the byte array of the bitmap, but I really need the format in YUV (NV21).FYI. the reason I'm asking this is because I have a camera app that supports rotation, but the frame previews are coming back in landscape mode only. 解决方案 The following method can rotate a YUV420 byte array by 90 degree.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;}(Note that this might only work if the width and height is a factor of 4) 这篇关于在 Android 上旋转 YUV 字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 00:21