我有一个存储为 byte[] 数组的图像,我想在将其发送到其他地方(作为 byte[] 数组)进行处理之前翻转该图像。
我四处搜索,无法找到不操作 byte[] 数组中每一位的简单解决方案。
将字节数组 [] 转换为某种图像类型,使用现有的翻转方法翻转它,然后将其转换回字节 [] 数组怎么样?
有什么建议吗?
Cheers!
字节数组到位图:
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
使用它通过提供直角 (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);
}
然后回到数组:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] flippedImageByteArray = stream.toByteArray();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)