2013-10-08 37 views
0

在Win8 App Store中,给定一个流,我怎样才能得到来自该流的图像的PixelFormat?我只能得到byte array, width, height, stride,但我还需要像素格式类型(例如,有多少位每像素,RGBA32 ...)创建某种BitmapSourceWin8 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 = ?????? 

我能做到这一点?

回答