0

如何通过使用可写位图从Windows应用商店中的图像获取RGB颜色百分比。从图像中获取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应用可写位做到这一点?

回答

1

退房BitmapDecoder班。它应该有你需要的一切。

基本上,像素数据异步获取,然后像你一样使用它。只是需要警告的是,有时候像素数据会保存在16位的块中(每个块有两个字节),所以你必须在字节数组上快速执行Linq调用才能将其变为可用的像素数组。