0

如何使用可写位图从 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 应用程序中使用可写位图做到这一点?

4

1 回答 1

1

查看BitmapDecoder课程。它应该有你需要的一切。

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

于 2013-08-19T20:14:53.717 回答