Java 将YUV字节数组图像调整为特定的宽度和高度

Java 将YUV字节数组图像调整为特定的宽度和高度,java,android,arrays,image,image-processing,Java,Android,Arrays,Image,Image Processing,我试图找到一种方法、方法或算法,将YUV图像缩小到特定的宽度和高度值,而不将其转换为RGB,只需操作我的YUV图像的字节[] 我刚刚找到了另一个关于这个的话题 我知道实现这一点的方法是去除像素,但我可以始终使用4的因子,因为色度像素在4个亮度像素之间共享 经过研究,我刚刚实现了下一种方法,即将YUV图像重新缩放为原始图像的四倍,但我想要实现的是将Width x Height分辨率自由转换为我想要的更小的分辨率,而不是4倍。有可能以某种方式实现这一点吗?我在使用Renderscript或任何类型

我试图找到一种方法、方法或算法,将YUV图像缩小到特定的宽度和高度值,而不将其转换为RGB,只需操作我的YUV图像的
字节[]

我刚刚找到了另一个关于这个的话题

我知道实现这一点的方法是去除像素,但我可以始终使用4的因子,因为色度像素在4个亮度像素之间共享

经过研究,我刚刚实现了下一种方法,即将
YUV图像重新缩放为原始图像的四倍,但我想要实现的是将
Width x Height分辨率
自由转换为我想要的更小的分辨率,而不是4倍。有可能以某种方式实现这一点吗?我在使用Renderscript或任何类型的库时都没有问题

/**
     * Rescale a YUV image four times smaller than the original image for faster processing.
     *
     * @param data        Byte array of the original YUV image
     * @param imageWidth  Width in px of the original YUV image
     * @param imageHeight Height in px of the original YUV image
     * @return Byte array containing the downscaled YUV image
     */
    public static byte[] quadYuv420(byte[] data, int imageWidth, int imageHeight) {
        Log.v(TAG, "[quadYuv420] receiving image with " + imageWidth + "x" + imageHeight);
        long startingTime = System.currentTimeMillis();
        byte[] yuv = new byte[imageWidth / 8 * imageHeight / 8 * 3 / 2];
        // process Y component
        int i = 0;
        for (int y = 0; y < imageHeight; y += 8) {
            for (int x = 0; x < imageWidth; x += 8) {
                yuv[i] = data[y * imageWidth + x];
                i++;
            }
        }
        // process U and V color components
        for (int y = 0; y < imageHeight / 2; y += 8) {
            for (int x = 0; x < imageWidth; x += 16) {
                if (i < yuv.length) {
                    yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + x];
                    i++;
                    yuv[i] = data[(imageWidth * imageHeight) + (y * imageWidth) + (x + 1)];
                    i++;
                }
            }
        }
        Log.v(TAG, "[quadYuv420] Rescaled YUV420 in " + (System.currentTimeMillis() - startingTime) + "ms");
        return yuv;
    }
/**
*重新缩放比原始图像小四倍的YUV图像,以加快处理速度。
*
*原始YUV图像的@param数据字节数组
*@param imageWidth原始YUV图像的px宽度
*@param imageHeight原始YUV图像的像素高度
*@return字节数组,包含缩小的YUV图像
*/
公共静态字节[]quadYuv420(字节[]数据,int-imageWidth,int-imageHeight){
Log.v(标签,“[quadYuv420]接收带“+imageWidth+”x“+imageHeight”的图像);
长启动时间=System.currentTimeMillis();
字节[]yuv=新字节[imageWidth/8*imageHeight/8*3/2];
//工艺Y组件
int i=0;
对于(int y=0;y
看看libyuv


您可能需要编写一个jni包装器,并使用项目中包含的转换函数将yuv转换为planar-

谢谢您,伙计,它确实帮助了我,现在我正在与librar进行斗争。看看我的新问题,看看你能否帮我一把: