Files
PowerToys/ImageResizer/test/ImageResizer.Test/Test/BitmapSourceExtensions.cs

27 lines
808 B
C#
Raw Normal View History

2020-01-02 16:57:27 -08:00
// <copyright file="BitmapSourceExtensions.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
using System.Windows;
2019-12-23 17:49:31 -08:00
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace ImageResizer.Test
{
static class BitmapSourceExtensions
{
public static Color GetFirstPixel(this BitmapSource source)
{
var pixel = new byte[4];
new FormatConvertedBitmap(
new CroppedBitmap(source, new Int32Rect(0, 0, 1, 1)),
PixelFormats.Bgra32,
destinationPalette: null,
alphaThreshold: 0)
.CopyPixels(pixel, 4, 0);
return Color.FromArgb(pixel[3], pixel[2], pixel[1], pixel[0]);
}
}
}