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調用才能將其變爲可用的像素數組。