当我运行这段代码时,我得到一个黑屏,直到我最大化应用程序?此外,我认为它也不会拾取图像文件。在Visual Studio中,我创建了一个新文件夹,并将图像添加到此文件夹中。
public MainWindow()
{
InitializeComponent();
Canvas canvas = new Canvas();
canvas.Width = 300;
canvas.Height = 300;
canvas1.Children.Add(canvas);
Ellipse hand = new Ellipse();
hand.Height = 30;
hand.Width = 30;
/*
BrushConverter bc = new BrushConverter();
Brush brush = (Brush)bc.ConvertFrom("Red");
hand.Fill = new SolidColorBrush(Colors.Red);
*/
ImageBrush myBrush = new ImageBrush();
myBrush.ImageSource =
new BitmapImage(new Uri(@"Images/Hand.png", UriKind.Relative));
hand.Fill = myBrush;
Canvas.SetLeft(hand, 100);
Canvas.SetTop(hand, 100);
canvas.Children.Add(hand);
}发布于 2012-03-12 03:25:25
您使用TextureBrush有什么特殊的原因吗?
不是很确定,但也许你应该使用ImageBrush。
ImageBrush myBrush = new ImageBrush();
myBrush.ImageSource =
new BitmapImage(new Uri("pack://application:,,,/Images/image.jpg"));
myEllipse.Fill = myBrush;https://stackoverflow.com/questions/9658051
复制相似问题