翻转存储为byte []数组的图像

LKB*_*LKB 7 java android image bytearray flip

我有一个存储为byte []数组的图像,我想在将其发送到其他地方(作为byte []数组)之前翻转图像.

我已经搜索过,在没有操作byte []数组中的每个位的情况下找不到简单的解决方案.

如何将字节数组[]转换为某种类型的图像类型,使用现有的翻转方法翻转,然后将其转换回byte []数组?

有什么建议?

干杯!

Voi*_*icu 10

字节数组到位图:

Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
Run Code Online (Sandbox Code Playgroud)

使用此选项通过提供直角(180)来旋转图像:

public Bitmap rotateImage(int angle, Bitmap bitmapSrc) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    return Bitmap.createBitmap(bitmapSrc, 0, 0, 
        bitmapSrc.getWidth(), bitmapSrc.getHeight(), matrix, true);
}
Run Code Online (Sandbox Code Playgroud)

然后回到数组​​:

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] flippedImageByteArray = stream.toByteArray();
Run Code Online (Sandbox Code Playgroud)