市集應用程式影像處理,遇到最關鍵的地方是如何讀取圖片串流後取得RGBData,後來在MSDN上找到範例程式
public static async Task LoadImage(StorageFile file) { using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream); // Scale image to appropriate size BitmapTransform transform = new BitmapTransform() { ScaledWidth = Convert.ToUInt32(decoder.PixelWidth), ScaledHeight = Convert.ToUInt32(decoder.PixelHeight) }; PixelDataProvider pixelData = await decoder.GetPixelDataAsync( BitmapPixelFormat.Bgra8, // WriteableBitmap uses BGRA format BitmapAlphaMode.Straight, transform, ExifOrientationMode.IgnoreExifOrientation, // This sample ignores Exif orientation ColorManagementMode.DoNotColorManage ); // An array containing the decoded image data, which could be modified before being displayed byte[] sourcePixels = pixelData.DetachPixelData(); // Open a stream to copy the image contents to the WriteableBitmap's pixel buffer await SetImage(decoder, sourcePixels, gray); return new { rgbData = sourcePixels, Width = decoder.PixelWidth, Height = decoder.PixelHeight }; } }
全站熱搜
留言列表