2014-09-28 55 views
0

请告诉我如何文本或字符串转换的位图图像WPF在C#。因为没有Bitmap类是可用的,如Windows窗体.. 感谢提前:)如何字符串转换为位图图像

+0

您仍然可以使用WPF中的WinForms中的位图类,在您的项目中添加对System.Drawing的引用,然后通过System.Drawing.Bitmap访问该类。 – learningcs 2014-09-29 23:34:29

回答

0

BitmapImage是你正在寻找。请参阅MSDN链接中提供的示例。

// Create the image element. 
Image simpleImage = new Image();  
simpleImage.Width = 200; 
simpleImage.Margin = new Thickness(5); 

// Create source. 
BitmapImage bi = new BitmapImage(); 
// BitmapImage.UriSource must be in a BeginInit/EndInit block. 
bi.BeginInit(); 
bi.UriSource = new Uri(@"/sampleImages/cherries_larger.jpg",UriKind.RelativeOrAbsolute); 
bi.EndInit(); 
// Set the image source. 
simpleImage.Source = bi; 

此外,您还可以直接设置在XAML的来源,WPF通过默认的转换器在内部转换为ImageSource的字符串到的ImageSource。

<Image Source="/sampleImages/cherries_larger.jpg"/>