PremultiplyComponents
RasterImage.PremultiplyComponents property
获取或设置一个值,该值指示是否必须对图像分量进行预乘。
public virtual bool PremultiplyComponents { get; set; }
适当的价值
真的
如果必须对图像分量进行预乘;否则,错误的
.
例子
下面的示例创建一个新的光栅图像,保存指定的半透明像素,然后加载这些像素并以预乘形式获取最终颜色。
[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.PngOptions createOptions = new Aspose.Imaging.ImageOptions.PngOptions();
createOptions.Source = new Aspose.Imaging.Sources.StreamSource(new System.IO.MemoryStream(), true);
createOptions.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Create(createOptions, imageWidth, imageHeight))
{
Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
// 保存整个图像的像素。
rasterImage.SavePixels(rasterImage.Bounds, colors);
// 像素以非预乘的形式存储在原始图像中。
// 需要显式指定相应的选项才能获得预乘的颜色分量。
// 预乘的颜色分量由以下公式计算:
// 红色 = original_red * alpha / 255;
// 绿色 = original_green * alpha / 255;
// 蓝色 = original_blue * alpha / 255;
rasterImage.PremultiplyComponents = true;
Aspose.Imaging.Color[] premultipliedColors = rasterImage.LoadPixels(rasterImage.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());
}
}
也可以看看
- class RasterImage
- 命名空间 Aspose.Imaging
- 部件 Aspose.Imaging