在android中旋转YUV420 / NV21图像

编程入门 行业动态 更新时间:2024-10-22 05:02:16
本文介绍了在android中旋转YUV420 / NV21图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在PreviewCall背面,我们在相机预览中得到了YUV420SP格式,但是由于该图像的旋转错误,我想要正确旋转YUV图像,因为我需要通过网络发送它。因此需要应用正确的旋转。

In PreviewCall back of surface we are getting YUV420SP format in camera Preview but due to wrong rotation of that image I want to perform correct rotation of YUV image as I need to send it through network.so correct rotation need to be applied.

我发现此链接确实正确旋转但图像颜色松散。

I found this link it does correct rotation but image loose the color.

http:// www .wordsaretoys / 2013/10/25 / roll-that-c​​amera-zombie-rotation-and-coversion-from-yv12-to-yuv420planar /

还检查了在Android上旋转YUV字节数组但它没有正确显示图像。

also checked Rotate an YUV byte array on Android but it does not show image properly.

我确实检查了stckoverflow上的链接,但没有一个人能够正确使用android环境中的代码。

I do have checked links on stckoverflow but none of them have satisfactory answer about correctly using the code in android environment.

do任何人都知道如何正确旋转NV21图像字节[]并正确保留其颜色信息。

do any one have idea how to correctly rotate NV21 Image bytes[] with retaining its color information correctly.

推荐答案

如果你只是想旋转NV21,以下代码会有所帮助。 (我修改了代码从这里开始)

If you just want to rotate NV21, following code will be helpful. (I modified the code from here)

public static void rotateNV21(byte[] input, byte[] output, int width, int height, int rotation) { boolean swap = (rotation == 90 || rotation == 270); boolean yflip = (rotation == 90 || rotation == 180); boolean xflip = (rotation == 270 || rotation == 180); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int xo = x, yo = y; int w = width, h = height; int xi = xo, yi = yo; if (swap) { xi = w * yo / h; yi = h * xo / w; } if (yflip) { yi = h - yi - 1; } if (xflip) { xi = w - xi - 1; } output[w * yo + xo] = input[w * yi + xi]; int fs = w * h; int qs = (fs >> 2); xi = (xi >> 1); yi = (yi >> 1); xo = (xo >> 1); yo = (yo >> 1); w = (w >> 1); h = (h >> 1); // adjust for interleave here int ui = fs + (w * yi + xi) * 2; int uo = fs + (w * yo + xo) * 2; // and here int vi = ui + 1; int vo = uo + 1; output[uo] = input[ui]; output[vo] = input[vi]; } } }

更多推荐

在android中旋转YUV420 / NV21图像

本文发布于:2023-11-30 20:40:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651413.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!