これは簡単なはずですが、それを行う方法が見つからないようです。カスタム描画を行うオーバーライドされたペイント メソッドを持つカスタム WinForms コントロールがあります。
メモリにビットマップがあり、HashBrush で全体をペイントするだけで、ビットマップの透明な部分がペイントされないようにアルファ チャネルを保持します。
メモリ内のビットマップは単純な形状ではないため、一連のパスなどとして定義することはできません。
編集: コードの表示に応じて、ペイント ルーチンには多くのコードがあるため、問題のメソッドである関連するスニペットのみを含めています。このメソッドは、メイン ペイント オーバーライドから呼び出されます。黒の透明マスクである画像のリストを受け取り、それらを 1 つに結合します。次に、ColorMatrix を使用して、作成した結合画像の色を変更し、背景の上に重ねることができるようにします。私が達成したいのは、その上にハッシュマークもペイントできるようにすることだけです。
private void PaintSurface(PaintEventArgs e, Image imgParent, List<Image> surfImgs, Rectangle destRect, ToothSurfaceMaterial material)
{
using (Bitmap bmp = new Bitmap(imgParent.Width, imgParent.Height,
System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
{
using (Graphics g = Graphics.FromImage(bmp))
{
foreach (Image img in surfImgs)
{
g.DrawImage(img, System.Drawing.Point.Empty);
}
}
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.7f, 0},
new float[] { material.R / 255.0f,
material.G / 255.0f,
material.B / 255.0f,
0, 1}
});
ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetColorMatrix(matrix);
Rectangle r = GetSizedRect(imgParent, destRect);
e.Graphics.DrawImage(bmp,
r,
0,
0,
bmp.Width,
bmp.Height,
GraphicsUnit.Pixel, imageAttr);
}
}