作为一个byte []数组存储翻转图像 [英] Flip image stored as a byte[] array
问题描述
我有被存储为一个byte []数组的形象,我想翻转图像之前,我把它送上在其他地方处理(如一个byte []数组)。
I have an image which is stored as a byte[] array, and I want to flip the image before I send it off to be processed elsewhere (as a byte[] array).
我已搜索周围,无法找到一个简单的解决方案,而无需操纵在byte []数组。
I've searched around and can't find a simple solution without manipulating each bit in the byte[] array.
怎么样的字节数组[]转换成某种形式的图像类型,翻转,使用现有的翻转方法,然后将那回一个byte []数组?
What about converting the byte array[] to an image type of some sort, flipping that using an existing flip method, and then converting that back to a byte[] array?
任何意见?
干杯!
推荐答案
字节数组位图:
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
使用通过提供合适的角度(180)旋转图像:
Use this to rotate the image by providing the right angle (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);
}
然后回到数组:
Then back to the array:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] flippedImageByteArray = stream.toByteArray();
这篇关于作为一个byte []数组存储翻转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!