PremultiplyComponents
TiffImage.PremultiplyComponents property
获取或设置一个值,该值指示是否必须对分量进行预乘。
public override bool PremultiplyComponents { get; set; }
适当的价值
真的
如果组件必须预乘;否则,错误的
.
例子
下面的示例创建一个新的 TIFF 图像,保存指定的半透明像素,然后加载这些像素并以预乘形式获取最终颜色。
[C#]
int imageWidth = 3;
int imageHeight = 2;
Aspose.Imaging.Color[] colors = new Aspose.Imaging.Color[]
{
Aspose.Imaging.Color.FromArgb(127, 255, 0, 0),
Aspose.Imaging.Color.FromArgb(127, 0, 255, 0),
Aspose.Imaging.Color.FromArgb(127, 0, 0, 255),
Aspose.Imaging.Color.FromArgb(127, 255, 255, 0),
Aspose.Imaging.Color.FromArgb(127, 255, 0, 255),
Aspose.Imaging.Color.FromArgb(127, 0, 255, 255),
};
Aspose.Imaging.ImageOptions.TiffOptions createOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.TiffDeflateRgba);
createOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream(), true);
using (Aspose.Imaging.FileFormats.Tiff.TiffImage image = (Aspose.Imaging.FileFormats.Tiff.TiffImage)Aspose.Imaging.Image.Create(createOptions, imageWidth, imageHeight))
{
// 保存整个图像的像素。
image.SavePixels(image.Bounds, colors);
// 像素以非预乘的形式存储在原始图像中。
// 需要显式指定相应的选项才能获得预乘的颜色分量。
// 预乘的颜色分量由以下公式计算:
// 红色 = original_red * alpha / 255;
// 绿色 = original_green * alpha / 255;
// 蓝色 = original_blue * alpha / 255;
image.PremultiplyComponents = true;
Aspose.Imaging.Color[] premultipliedColors = image.LoadPixels(image.Bounds);
for (int i = 0; i < colors.Length; i++)
{
System.Console.WriteLine("Original color: {0}", colors[i].ToString());
System.Console.WriteLine("Premultiplied color: {0}", premultipliedColors[i].ToString());
}
}
//输出将如下所示:
//原色:Color [A=127, R=255, G=0, B=0]
//预乘颜色:Color [A=127, R=127, G=0, B=0]
//原色:Color [A=127, R=0, G=255, B=0]
//预乘颜色:Color [A=127, R=0, G=127, B=0]
//原色:Color [A=127, R=0, G=0, B=255]
//预乘颜色:Color [A=127, R=0, G=0, B=127]
//原色:Color [A=127, R=255, G=255, B=0]
//预乘颜色:Color [A=127, R=127, G=127, B=0]
//原色:Color [A=127, R=255, G=0, B=255]
//预乘颜色:Color [A=127, R=127, G=0, B=127]
//原色:Color [A=127, R=0, G=255, B=255]
//预乘颜色:Color [A=127, R=0, G=127, B=127]
也可以看看
- class TiffImage
- 命名空间 Aspose.Imaging.FileFormats.Tiff
- 部件 Aspose.Imaging