简体   繁体   中英

How to convert string to bitmap image

请告诉我如何在c#中的wpf中转换位图图像中的文本或字符串。因为没有像Windows窗体一样可用的位图类。.感谢Advance :)

BitmapImage is what you are looking for. Refer to the sample provided in MSDN link.

// 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;

Also, you can set the source directly in XAML which WPF internally convert to ImageSource via default converter for String to ImageSource.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM