彩色矩阵可以是此处有用:
private Image tooth = Image.FromFile(@"c:\...\tooth.png");
private Image maskBMP = Image.FromFile(@"c:\...\toothMask.png");
protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
e.Graphics.DrawImage(tooth, Point.Empty);
using (Bitmap bmp = new Bitmap(maskBMP.Width, maskBMP.Height,
PixelFormat.Format32bppPArgb)) {
// Transfer the mask
using (Graphics g = Graphics.FromImage(bmp)) {
g.DrawImage(maskBMP, Point.Empty);
}
Color color = Color.SteelBlue;
ColorMatrix matrix = new ColorMatrix(
new float[][] {
new float[] { 0, 0, 0, 0, 0},
new float[] { 0, 0, 0, 0, 0},
new float[] { 0, 0, 0, 0, 0},
new float[] { 0, 0, 0, 0.5f, 0},
new float[] { color.R/255.0f,
color.G/255.0f,
color.B/255.0f,
0, 1}
});
ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetColorMatrix(matrix);
e.Graphics.DrawImage(bmp,
new Rectangle(Point.Empty, bmp.Size),
0,
0,
bmp.Width,
bmp.Height,
GraphicsUnit.Pixel, imageAttr);
}
}
在矩阵声明的0.5F值是α值。
您正在研究牙科应用程序吗?棒极了! – sircapsalot
目前尚不清楚为什么要使用面具。只需使用Graphics.FillRectangle(),使用您创建的SolidBrush,并使用alpha值小于255的Color创建。 –
对此类事物的一个很好的研究是Paint.NET的最后一个开源版本 - https://代码.google.com/p/openpdn/source/checkout –