繁体   English   中英

从图像获取RGB颜色百分比

[英]Get RGB Color Percentage From Image

如何使用可写位图从Windows应用程序商店中的图像获取RGB颜色百分比。

在Windows应用程序中,我像这样早点得到它:

public static Color getDominantColor(Bitmap bmp)
{

       //Used for tally
       int r = 0;
       int g = 0;
       int b = 0;

     int total = 0;

     for (int x = 0; x < bmp.Width; x++)
     {
          for (int y = 0; y < bmp.Height; y++)
          {
               Color clr = bmp.GetPixel(x, y);

               r += clr.R;
               g += clr.G;
               b += clr.B;

               total++;
          }
     }

     //Calculate average
     r /= total;
     g /= total;
     b /= total;

     return Color.FromArgb(r, g, b);
}

如何在Metro App中使用可写位图执行此操作?

BitmapDecoderBitmapDecoder类。 它应该具有您需要的一切。

基本上,异步获取像素数据,然后按需使用它。 请注意,有时像素数据以16位块(每个2个字节)的形式保存,因此您必须对字节数组进行快速Linq调用才能将其转换为可用的像素数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM