0
A
回答
-1
Color color1 = Color.FromArgb(UInt1);
Color color2 = Color.FromArgb(UInt2);
Color averageColor = Color.FromArgb(255,(color1.R + color2.R)/2,(color1.G + color2.G)/2,(color1.B + color2.B)/2);
這是假設你需要一個完全不透明的平均顏色。
1
從技術上講,您可能在色彩映射設備上運行,這意味着您需要通過X11色彩管理來處理所有這些。您需要查詢XColor
您的兩個輸入顏色,計算平均值,然後查找最接近的可表現的顏色:
// Query XColor for both input colors
XColor xcol1, xcol2, outcol;
xcol1.pixel = color1;
xcol2.pixel = color2;
XQueryColor(display, colormap, &xcol1);
XQueryColor(display, colormap, &xcol2);
// Average red/green/blue and look up nearest representable color
outcol.red = (xcol1.red + xcol2.red)/2;
outcol.green = (xcol1.green + xcol2.green)/2;
outcol.blue = (xcol1.blue + xcol2.blue)/2;
XAllocColor(display, colormap, &outcol);
// outcol.pixel is now the color to use
在有調色板的設備,還需要事後釋放顏色等 - 這是一個爛攤子,基本上。
但是很可能你使用的是32位真彩色設備,這意味着整數只是r,g,b和a(不一定按順序)的位域。你可以像這樣計算它們的平均值:
UInt out_color = 0;
for (int i=0; i < 4; i++) {
// Extract channel i from both input colors
UInt in1 = (color1 >> (i*8)) & 0xff;
UInt in2 = (color2 >> (i*8)) & 0xff;
// Compute the average and or it into the output color
out_color |= ((in1 + in2)/2) << (i*8);
}
相關問題
- 1. Mac Screen的平均顏色
- 2. 顏色平均線ggplot
- 3. K平均聚類顏色不變
- 4. php平均顏色圖像PNG格式
- 5. 從bmp獲取平均顏色
- 6. řbeanplot改變顏色和平均線
- 7. 顏色[,]在C#中的平均
- 8. 恆星的平均顏色是多少?
- 9. 圖像的RGB顏色的平均值
- 10. 在ImageJ /斐濟平均顏色
- 11. Haskell opengl紋理只有平均顏色
- 12. 查找圖像的平均顏色
- 13. 這種顏色在哪個X11顏色範圍內
- 14. 將HTML HEX顏色或RGB元組轉換爲X11顏色
- 15. photoshop如何計算圖像的「平均模糊」(平均顏色)?
- 16. 獲取圖片的平均顏色和使用java比較圖片顏色
- 17. 基於整個色譜柱平均值的顏色細胞
- 18. 在多色背景上顯示的img的平均顏色
- 19. dc.js顏色餅圖顏色與顏色域的顏色
- 20. 顏色和顏色名稱
- 21. 隨機顏色從顏色
- 22. ASCII顏色爲HEX顏色
- 23. 改變顏色的顏色
- 24. 爲顏色添加顏色
- 25. geom_line中的平滑顏色
- 26. 展平PowerPoint重點顏色?
- 27. SDL網格顏色平滑
- 28. 雙色顏色
- 29. 顏色色板
- 30. 如何在片段着色器中結合紋理顏色和均勻顏色?
-1。這不是Xlib代碼,也不是針對任何X11窗口工具包的代碼。 – 2010-11-14 00:35:19
你的問題中沒有提到X11。 – Flipster 2010-11-14 01:15:32
這個問題被稱爲「平均顏色(X11顏色)」,並標記爲「x11」和「xlib」 - 這是非常明確的。 – 2010-11-14 03:35:47