/
BitmapMixins.cs
35 lines (32 loc) · 1.25 KB
/
BitmapMixins.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using System.Windows.Media.Imaging;
namespace Splat
{
/// <summary>
/// Extension methods to assist with dealing with Bitmaps.
/// </summary>
public static class BitmapMixins
{
/// <summary>
/// Converts <see cref="IBitmap"/> to a native type.
/// </summary>
/// <param name="value">The bitmap to convert.</param>
/// <returns>A <see cref="BitmapSource"/> bitmap.</returns>
public static IBitmap FromNative(this BitmapSource value)
{
return new BitmapSourceBitmap(value);
}
/// <summary>
/// Converts a <see cref="BitmapSource"/> to a splat <see cref="IBitmap"/>.
/// </summary>
/// <param name="value">The native bitmap to convert from.</param>
/// <returns>A <see cref="IBitmap"/> bitmap.</returns>
public static BitmapSource ToNative(this IBitmap value)
{
return ((BitmapSourceBitmap)value).Inner;
}
}
}