0

在 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 = ??????

我可以这样做吗?

4

1 回答 1

0

我发现我可以使用 BitmapDecoder 来获取 PixelFormat 信息:http: //msdn.microsoft.com/en-us/library/windows/apps/jj709939.aspx

于 2013-10-08T11:22:31.143 回答