I'm new to UWP app development and trying to build an image processing app. I was using the code in https://msdn.microsoft.com/en-us/windows/uwp/audio-video-camera/imaging However I got exception like this:
SoftwareBitmapSource::SetBitmapAsync only supports SoftwareBitmap with positive width/height, bgra8 pixel format and pre-multiplied or no alpha. in code await source.SetBitmapAsync(sbitmap);
I'm wondering if this method really has so many limitations and if so if there is any alternative I should use that has the least limitations. The code snippet is as following
FileOpenPicker fileOpenPicker = new FileOpenPicker();
fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
fileOpenPicker.FileTypeFilter.Add(".jpg");
fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
var inputFile = await fileOpenPicker.PickSingleFileAsync();
if(inputFile != null)
{
SoftwareBitmap sbitmap;
using (IRandomAccessStream stream = await inputFile.OpenAsync(FileAccessMode.Read))
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
sbitmap = await decoder.GetSoftwareBitmapAsync();
}
var source = new SoftwareBitmapSource();
await source.SetBitmapAsync(sbitmap);
**Exception--->**imageControl.Source = source;
}
This is a known issue. For now you can workaround this by using SoftwareBitmap.Convert to get a Bgra8 pre-multiplied SoftwareBitmap to display
SoftwareBitmap displayableImage = SoftwareBitmap.Convert(sbitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With