PaulLYang
2018-06-06 11:48
采纳率: 50%
浏览 3.9k

Android平台下怎么把JPEG格式的图片转化成NV21

如题,Android平台下怎么把JPEG格式的图片转化成NV21?

请大神指点一下。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • blownewbee 2018-06-06 15:08

    参考:https://stackoverflow.com/questions/5960247/convert-bitmap-array-to-yuv-ycbcr-nv21
    至于jpeg->bitmap,这个代码很好找吧。

    点赞 评论
  • 大锟少 2018-06-07 00:47

    先转为 base 64

    点赞 评论
  • 邪恶八进制 2018-06-07 01:25

    按照下面的方式应该可以得到解决:

     void yourFunction(){
    
        // mBitmap is your bitmap
    
        int mWidth = mBitmap.getWidth();
        int mHeight = mBitmap.getHeight();
    
        int[] mIntArray = new int[mWidth * mHeight];
    
        // Copy pixel data from the Bitmap into the 'intArray' array
        mBitmap.getPixels(mIntArray, 0, mWidth, 0, 0, mWidth, mHeight);
    
        // Call to encoding function : convert intArray to Yuv Binary data
        encodeYUV420SP(data, intArray, mWidth, mHeight);
    
    }
    
    static public void encodeYUV420SP(byte[] yuv420sp, int[] rgba,
            int width, int height) {
        final int frameSize = width * height;
    
        int[] U, V;
        U = new int[frameSize];
        V = new int[frameSize];
    
        final int uvwidth = width / 2;
    
        int r, g, b, y, u, v;
        for (int j = 0; j < height; j++) {
            int index = width * j;
            for (int i = 0; i < width; i++) {
    
                r = Color.red(rgba[index]);
                g = Color.green(rgba[index]);
                b = Color.blue(rgba[index]);
    
                // rgb to yuv
                y = (66 * r + 129 * g + 25 * b + 128) >> 8 + 16;
                u = (-38 * r - 74 * g + 112 * b + 128) >> 8 + 128;
                v = (112 * r - 94 * g - 18 * b + 128) >> 8 + 128;
    
                // clip y
                yuv420sp[index] = (byte) ((y < 0) ? 0 : ((y > 255) ? 255 : y));
                U[index] = u;
                V[index++] = v;
            }
        }
    
    点赞 评论
  • PaulLYang 2018-06-08 01:20

    问题解决了!
    感谢各位的思路,https://github.com/gqjjqg/android-extend

    点赞 评论

相关推荐 更多相似问题