0
在Win8 App Store中,給定一個流,我怎樣才能得到來自該流的圖像的PixelFormat
?我只能得到byte array, width, height, stride
,但我還需要像素格式類型(例如,有多少位每像素,RGBA32 ...)創建某種BitmapSource
:Win8 App Store - 如何獲得PixelFormat?
//Copy photo from camera to stream
var fPhotoStream = new InMemoryRandomAccessStream();
await mediaCaptureMgr.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), fPhotoStream);
await fPhotoStream.FlushAsync();
fPhotoStream.Seek(0);
//Convert stream to byte array
byte[] bytes = new byte[fPhotoStream.Size];
await fPhotoStream.ReadAsync(bytes.AsBuffer(), (uint)fPhotoStream.Size, InputStreamOptions.None);
//Get pointer to byte array
GCHandle pinnedArray = GCHandle.Alloc(bytes, GCHandleType.Pinned);
IntPtr pointer = pinnedArray.AddrOfPinnedObject();
//Get image width, height, stride
BitmapImage bmp = new BitmapImage();
bmp.SetSource(fPhotoStream);
int imgWidth = bmp.PixelWidth;
int imgHeight = bmp.PixelHeight;
int stride = bmp.Width * 4;
//But how to get image pixel format?
int pixelFormat = ??????
我能做到這一點?