Advertisement
xJeex

[EE] - GetBlockColor

Sep 8th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. private static uint GetBlockColor(Bitmap bmd) {
  2.     uint r = 0, g = 0, b = 0;
  3.  
  4.     for (int x = 0; x < bmd.Height; x++){
  5.         for (int y = 0; y < bmd.Width; y++){
  6.             uint color = ColorToUInt(bmd.GetPixel(x, y));
  7.  
  8.             r += (color & 0xff0000) >> 16;
  9.             g += (color & 0x00ff00) >> 8;
  10.             b += (color & 0x0000ff);
  11.         }
  12.     }
  13.  
  14.     r /= (uint)(bmd.Width * bmd.Height); //256
  15.     g /= (uint)(bmd.Width * bmd.Height); //256
  16.     b /= (uint)(bmd.Width * bmd.Height); //256
  17.  
  18.     return 0xff000000 | (r << 16) | (g << 8) | (b << 0);
  19. }
  20.  
  21. private static uint ColorToUInt(Color color) => (uint)((color.A << 24) | (color.R << 16) | (color.G << 8) | (color.B << 0));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement