FromArgb和FromScRgb [英] FromArgb vs FromScRgb
本文介绍了FromArgb和FromScRgb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这两个表达式的颜色是否应该大致相同?
Should these two expressions result in colors which are roughly the same?
Color.FromArgb(255, 255, 255, (byte)0.25 * 255))
Color.FromScRgb(1.0f, 1.0f, 1.0f, 0.25f))
此测试程序演示了它们显示的看似不同的alpha值:
This test program demonstrates that they show up with seemingly different alpha values:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace Test_FromArgb_FromScRbg
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var panel = new StackPanel();
Content = panel;
panel.Children.Add(
new Rectangle()
{
Width = 100,
Height = 100,
Fill = new SolidColorBrush(
Color.FromArgb(
255,
255,
255,
(byte)0.25 * 255))
});
panel.Children.Add(
new Rectangle()
{
Width = 100,
Height = 100,
Fill = new SolidColorBrush(
Color.FromScRgb(
1.0f,
1.0f,
1.0f,
0.25f))
});
}
}
}
这是演示程序在我的系统上的样子:
Here's what the demo program looks like on my system:
推荐答案
上面的mzzzzb提到了其背后的基本原因:
The basic reason behind this is mentioned by mzzzzb above:
比例尺0.0-1.0不会线性映射到0-255
the scale 0.0 - 1.0 does not map linearly to 0 - 255
即ScRgb成分与Argb成分不是线性映射.
I.e. the ScRgb components do not map linearly to the Argb components.
这篇关于FromArgb和FromScRgb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文