Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在UWP中使用颜色窃贼_C#_Colors_Uwp_Color Thief - Fatal编程技术网

C# 如何在UWP中使用颜色窃贼

C# 如何在UWP中使用颜色窃贼,c#,colors,uwp,color-thief,C#,Colors,Uwp,Color Thief,我加载的图像源于互联网,我需要这个图像的主色调。例如图像,然后发现颜色小偷,但我不能理解 我使用这种方法,但我认为它是错误的 BitmapDecoder BMD = new BitmapDecoder("https://yt3.ggpht.com/-cYK4gMKhvV0/AAAAAAAAAAI/AAAAAAAAAAA/8znlvBw-Wos/s100-c-k-no-mo-rj-c0xffffff/photo.jpg"); var colorThief = new ColorThief(); a

我加载的图像源于互联网,我需要这个图像的主色调。例如图像,然后发现颜色小偷,但我不能理解

我使用这种方法,但我认为它是错误的

BitmapDecoder BMD = new BitmapDecoder("https://yt3.ggpht.com/-cYK4gMKhvV0/AAAAAAAAAAI/AAAAAAAAAAA/8znlvBw-Wos/s100-c-k-no-mo-rj-c0xffffff/photo.jpg");
var colorThief = new ColorThief();
await colorThief.GetColor(BMD);
如何执行此操作?

的GetColor方法需要一个参数,这是正确的。但BitmapDecode并不是按照您尝试的方式创建的。BitmapDecoder可以根据方法创建,不能直接由Uri创建。所以首先需要一个RandomAccessStream对象。这可以通过创建一个RandomAccessStreamReference by来完成,然后打开并读取它。使用ColorTheep的完整演示如下所示,您可以参考:

Uri imageUri = new Uri("https://yt3.ggpht.com/-cYK4gMKhvV0/AAAAAAAAAAI/AAAAAAAAAAA/8znlvBw-Wos/s100-c-k-no-mo-rj-c0xffffff/photo.jpg");
RandomAccessStreamReference random = RandomAccessStreamReference.CreateFromUri(imageUri);
using (IRandomAccessStream stream = await random.OpenReadAsync())   
{
    //Create a decoder for the image
    var decoder = await BitmapDecoder.CreateAsync(stream);
    var colorThief = new ColorThief();
    var color = await colorThief.GetColor(decoder);       
}