int totalBytes = stride * height; for (int i = 0; i < totalBytes; i++) { int modulo = i % 4; if (modulo == 0) reorderedData[i + 3] = imageData[i]; else if (modulo == 1) reorderedData[i - 1] = imageData[i]; else if (modulo == 2) reorderedData[i - 1] = imageData[i]; else if (modulo == 3) reorderedData[i - 1] = imageData[i]; }