我正在實現一個Xamarin Android應用程序,它執行一些圖像操作。我加載一個位圖,將其轉換爲RGBA字節數組(每像素4個字節),然後我想將這個字節數組重新轉換爲位圖。在Android中,BitmapFactory.DecodeByteArray爲RGBA字節數組返回null
由於我在做像素操作的本質,我不想處理JPEG或PNG壓縮字節數組。它必須是RGBA。
下面是一些代碼,演示了我的問題,減少到最低限度:
var size = bitmap.Height * bitmap.RowBytes;
var buffer = ByteBuffer.Allocate(size);
bitmap.CopyPixelsToBuffer(buffer);
buffer.Rewind();
var bytes = new byte[size];
buffer.Get(bytes, 0, bytes.Length);
// At this point, bytes is an RGBA byte array, and I verified
// that the bytes are consistent with the image.
// Why doesn't this work?
var bitmap1 = BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length);
// Or this?
var imageStream = new MemoryStream(bytes);
var bitmap2 = BitmapFactory.DecodeStream(imageStream);
什麼是Android的方式來重新從RGBA字節數組位圖?
補充信息:在iOS中,我使用了RGB顏色空間(CGColorSpace.CreateDeviceRGB())的CGBitmapContext。在Windows 10中,我使用了一個WriteableBitmap。 Android中有什麼等價物?
感謝 洛朗