OnPreviewCallback方法的摄像头方向问题

时间:2018-04-12 12:36:26

标签: android android-camera

您好我正在实施here的ipStreaming代码 但问题是90度方向[使用纵向模式]视频翻转不是正确的方向。

尝试解决方案: -

1)nv21Converter

输出是: - enter image description here

2。)SO_Solution

输出是: -

public static byte[] rotateNV21(final byte[] yuv,
                            final int width,
                            final int height,
                                [![final int rotation)
{
  if (rotation == 0) return yuv;
  if (rotation % 90 != 0 || rotation < 0 || rotation > 270) {
    throw new IllegalArgumentException("0 <= rotation < 360, rotation % 90 == 0");
  }

  final byte\[\]  output    = new byte\[yuv.length\];
  final int     frameSize = width * height;
  final boolean swap      = rotation % 180 != 0;
  final boolean xflip     = rotation % 270 != 0;
  final boolean yflip     = rotation >= 180;

  for (int j = 0; j < height; j++) {
    for (int i = 0; i < width; i++) {
      final int yIn = j * width + i;
      final int uIn = frameSize + (j >> 1) * width + (i & ~1);
      final int vIn = uIn       + 1;

      final int wOut     = swap  ? height              : width;
      final int hOut     = swap  ? width               : height;
      final int iSwapped = swap  ? j                   : i;
      final int jSwapped = swap  ? i                   : j;
      final int iOut     = xflip ? wOut - iSwapped - 1 : iSwapped;
      final int jOut     = yflip ? hOut - jSwapped - 1 : jSwapped;

      final int yOut = jOut * wOut + iOut;
      final int uOut = frameSize + (jOut >> 1) * wOut + (iOut & ~1);
      final int vOut = uOut + 1;

      output\[yOut\] = (byte)(0xff & yuv\[yIn\]);
      output\[uOut\] = (byte)(0xff & yuv\[uIn\]);
      output\[vOut\] = (byte)(0xff & yuv\[vIn\]);
    }
  }
  return output;
}][4]][4]

输出为: -

enter image description here

0 个答案:

没有答案