Happy Day
Happy Day

Reputation: 307

How to Tile a Shape with Image and Texture Mask?

How i can apply a FillRectangle with texture Brush to source image via using Texture Mask?

Something like that... but how to use a texture mask?

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

Outfit: enter image description here And his mask: enter image description here Textile texture: enter image description here And how it should looks after, on output: enter image description here

Any ideas how it should looks for System.Drawing?

Upvotes: 0

Views: 182

Answers (1)

Baskar John
Baskar John

Reputation: 726

using the mask image, make transparent for the given colours and combine the images as follows.

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

Only you need to fill the rectangle with texture image

//what i should to do next and how to apply FillRectangle?
using (Graphics g = Graphics.FromImage(outfit))
{
    g.FillRectangle(textileBrush,g.ClipBounds);
}

Upvotes: 1

Related Questions