代码之家  ›  专栏  ›  技术社区  ›  Happy Day

如何使用图像和纹理遮罩平铺形状?

  •  0
  • Happy Day  · 技术社区  · 6 年前

    如何使用纹理蒙版将带有纹理画笔的圆角矩形应用于源图像?

    像这样…但是如何使用纹理面膜呢?

        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, ???, ???));
        }
    

    装备: enter image description here 他的面具: enter image description here 织物纹理: enter image description here 以及在输出时应如何处理: enter image description here

    有什么想法它应该如何寻找系统。绘图?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Baskar John    6 年前

    使用遮罩图像,使给定颜色透明,并按以下方式组合图像。

    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);
    }