开发者

Can I use Bitmap in a Brush, in Visual C#?

开发者 https://www.devze.com 2023-03-06 00:13 出处:网络
I want to use a picture instead of 开发者_StackOverflow中文版color in this code: brush = new SolidBrush(Color.Red);

I want to use a picture instead of 开发者_StackOverflow中文版color in this code:

brush = new SolidBrush(Color.Red);

Ex: brush = new SolidBrush(PICTURE);

What should I do?


Maybe you can use one of the Fill methods in Graphics class and a TextureBrush?

Image image = Image.FromFile("bitmap file path");
TextureBrush textureBrush = new TextureBrush(image);
graphics.FillEllipse(myTextureBrush, 0, 0, 200, 200);


You could use the TextureBrush to do so

private void Button2_Click(System.Object sender, System.EventArgs e)
{
    try
    {
        Bitmap image1 = (Bitmap) Image.FromFile(@"C:\Documents and Settings\" +
            @"All Users\Documents\My Music\music.bmp", true);

        TextureBrush texture = new TextureBrush(image1);
        texture.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
        Graphics formGraphics = this.CreateGraphics();
        formGraphics.FillEllipse(texture, 
            new RectangleF(90.0F, 110.0F, 100, 100));
        formGraphics.Dispose();

    }
    catch(System.IO.FileNotFoundException)
    {
        MessageBox.Show("There was an error opening the bitmap." +
            "Please check the path.");
    }

}

Code snippet taken from MSDN.


Use ImageBrush.

Can I use Bitmap in a Brush, in Visual C#?

0

精彩评论

暂无评论...
验证码 换一张
取 消