在 Win8 App Store 中,给定一个流,我如何PixelFormat
从该流中获取图像?我只能得到byte array, width, height, stride
,但我还需要像素格式类型(例如每个像素有多少位,rgba32 ...)来创建某种BitmapSource
:
//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 = ??????
我可以这样做吗?