如何通过使用纹理蒙版将纹理画笔的FillRectangle应用于源图像?
类似的东西......但是如何使用纹理蒙版?
Bitmap textile = new Bitmap("textile.png");
TextureBrush textileBrush = new TextureBrush(textile);
Bitmap outfit = new Bitmap("outfit.png");
Bitmap masksource = new Bitmap("mask.png");
Color bodyColorKey = Color.FromArgb(0, 255, 0);
//what i should to do next and how to apply FillRectangle?
using (Graphics g = Graphics.FromImage(outfit))
{
g.FillRectangle(textileBrush, new Rectangle(0, 0, ???, ???));
}
任何想法应该如何查找System.Drawing?
答案 0 :(得分:1)
使用蒙版图像,使给定颜色透明并按如下方式组合图像。
Bitmap textile = new Bitmap("textile.png");
TextureBrush textileBrush = new TextureBrush(textile);
Bitmap outfit = new Bitmap("outfit.png");
Bitmap masksource = new Bitmap("mask.png");
Bitmap transparentImage = new Bitmap(outfit.Width, outfit.Height);
masksource.MakeTransparent(Color.FromArgb(255, 0, 255, 0));
using (Graphics g = Graphics.FromImage(transparentImage))
{
g.DrawImage(outfit, new Point(0, 0));
//g.DrawImage(textile, new Point(0, 0)); // use texture image
g.FillRectangle(textileBrush, g.ClipBounds); // use texture image as Tile mode
g.DrawImage(masksource, new Point(0, 0));
transparentImage.MakeTransparent(Color.FromArgb(255, 255, 0, 0));
transparentImage.MakeTransparent(Color.FromArgb(255, 0, 0, 255));
}
Bitmap outputImage = new Bitmap(outfit.Width, outfit.Height);
using (Graphics g = Graphics.FromImage(outputImage))
{
g.DrawImage(outfit, new Point(0, 0));
g.DrawImage(transparentImage, new Point(0, 0));
}
只需要用纹理图像填充矩形
//what i should to do next and how to apply FillRectangle?
using (Graphics g = Graphics.FromImage(outfit))
{
g.FillRectangle(textileBrush,g.ClipBounds);
}