This repository has been archived on 2022-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
DevOpsOpenHack/MobileApps/MyDriving/MyDriving.UWP/Helpers/BitmapImageConverter.cs

28 lines
908 B
C#
Raw Normal View History

2022-11-03 20:41:13 +00:00
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media.Imaging;
namespace MyDriving.UWP.Helpers
{
public class BitmapImageConverter
{
//converts byte[] to BitmapImage
public static BitmapImage ConvertImage(byte[] pictureBytes)
{
if (pictureBytes == null) return null;
using (var ms = new InMemoryRandomAccessStream())
{
using (var writer = new DataWriter(ms.GetOutputStreamAt(0)))
{
writer.WriteBytes(pictureBytes);
writer.StoreAsync().GetResults();
}
var image = new BitmapImage();
image.SetSource(ms);
return image;
}
}
}
}