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.
精彩评论