Win8 应用商店 - 如何获取像素格式
本文关键字:获取 像素 格式 何获取 应用 Win8 | 更新日期: 2023-09-27 18:34:23
在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 = ??????
我能做到吗?
我发现我可以使用BitmapDecoder来获取PixelFormat信息:http://msdn.microsoft.com/en-us/library/windows/apps/jj709939.aspx