我有一个存储为byte []数组的图像,我想在将字节写入其他地方的磁盘之前垂直翻转图像.
图像字节来自压缩的jp2图像文件.我已经研究过像Flip图像存储为byte []数组这样的东西,但是我没有在android中工作,也没有访问BitmapFactory.我还考虑首先将字节数组转换为BufferedImage,然后翻转它,但是在当前上下文中不知道图像的高度和宽度(编辑:我修改了代码,因此高度和宽度都是现在已知).
有没有办法通过严格的数组操作来做到这一点?
编辑:尝试翻转代码
public static byte[] flip(byte[] imageBytes) {
//separate out the sub arrays
byte[] holder = new byte[imageBytes.length];
byte[] subArray = new byte[dimWidth];//dimWidth is the image width, or number of matrix columns
int subCount = 0;
for (int i = 0; i < imageBytes.length; i++) {
subArray[subCount] = imageBytes[i];
subCount++;
if (i% dimWidth == 0) {
subArray = reverse(subArray);
if (i == (dimWidth)) {
holder = subArray;
} else {
holder = concat(holder, subArray); …Run Code Online (Sandbox Code Playgroud)