Tag: imagesource

从资源文件设置image.Source

private void SetCredentials() { username = txtfromEmail.Text; password = txtpassword.Text; pictureLogin.Source = @”C:\Users\Sergio\Documents\Visual Studio 2008\Projects\emailwpf\emailwpf\ok.png”; } 我收到一个错误: “Cannot convert string to ImageSource” 。 我能做什么?

在Metro应用程序中以编程方式设置图像源,图像不会出现

我的应用程序中有一个主页面和一个相机页面。 主页面的图像没有源设置和按钮。 如果单击该按钮,将转到相机页面。 在相机页面上,我捕获图像并将其保存在平板电脑上的图片库中,然后导航回主页面,我想将图像源设置为刚拍摄并保存在图片库中的图像。 这是我的相关代码。 MainPage.xaml中 MainPage.xaml.cs中 private void img_OnLoaded(object sender, RoutedEventArgs e) { if (txtFirstName.Text != “” && txtLastName.Text != “”) { try { imgResume.Source = ImageFromRelativePath(this, Windows.Storage.KnownFolders.PicturesLibrary.Path + ((App)Application.Current).candidate.FirstName + ((App)Application.Current).candidate.FirstName + “Resume.jpg”); imgResume.UpdateLayout(); } catch { imgResume.Source = ImageFromRelativePath(this, @”Assets/logo.png”); imgResume.UpdateLayout(); } btnCamera.IsEnabled = true; } } public static BitmapImage ImageFromRelativePath(FrameworkElement parent, […]

根据文件扩展名获取默认的巨型系统图标

解决了! 有关工作代码,请参阅编辑2。 基于此站点的代码和freundblase在同一站点中所做的评论,我有以下类来获取基于文件扩展名的jumbo默认图标: // Original bad code removed 我试图以下列方式使用该类: preview.ImageSource = IconManager.GetIcon(“.pdf”, true); 其中预览是一个ImageBrush对象。 但我得到以下图像: 是的,我尝试使用pdf文件等注册文件类型。 怎么了? TIA – 编辑1: 我认为该图标用于未注册的文件类型。 如果我使用实际文件,我会得到一个FileNotFoundException。 – 编辑2: 在发布此问题之前,我使用ReSharper进行了代码清理。 我根据站点代码和freundblase评论重新上课,现在它正在运行! 我必须仔细分析ReSharper所做的更改。 代码清理从来没有给我任何问题。 对于后代,以下代码有效: public class IconManager { // Constants that we need in the function call private const int SHGFI_ICON = 0x100; private const int SHGFI_LARGEICON = 0x0; private […]

WPF绑定图像源

也许是愚蠢的问题,但我不知道…… 我有这样的ViewModel类: public class MainWindowsViewModel : INotifyPropertyChanged { private ImageSource _img; public ImageSource StatusImage { get { return _img; } set { _img = value; NotifyPropertyChanged(); } } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged([CallerMemberName]String propertyName = “”) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } XAML中的绑定看起来像这样: 我将ImageSource的内容设置为: MainWindowsViewModel _view = new MainWindowsViewModel(); […]

WPF – 将Bitmap转换为ImageSource

我需要将System.Drawing.Bitmap转换为System.Windows.Media.ImageSource类,以便将其绑定到WizardPage(扩展WPF工具包)的HeaderImage控件中。 位图设置为我编写的程序集的资源。 它被引用如下: public Bitmap GetBitmap { get { Bitmap bitmap = new Bitmap(Resources.my_banner); return bitmap; } } public ImageSource HeaderBitmap { get { ImageSourceConverter c = new ImageSourceConverter(); return (ImageSource) c.ConvertFrom(GetBitmap); } } 这个转换器是我在这里找到的: http : //www.codeproject.com/Questions/621920/How-to-convert-Bitmap-to-ImageSource我得到一个NullReferenceException return (ImageSource) c.ConvertFrom(Resources.my_banner); 如何初始化ImageSource以避免此exception? 或者还有另一种方式吗? 我希望之后使用它: <xctk:WizardPage x:Name="StartPage" Height="500" Width="700" HeaderImage="{Binding HeaderBitmap}" Enter="StartPage_OnEnter" 提前感谢您的任何答案。

使用IValueConverter动态加载图像源

我有IValueconverter的问题并动态加载行网格图像: public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string Type = (string)value; Uri uri; try { uri = new Uri(“/XConsole;component/Images/” + Type + “.png”, UriKind.Relative); return new System.Windows.Media.Imaging.BitmapImage(uri) { CacheOption = BitmapCacheOption.None }; } catch (Exception e) { //donothing } uri = new Uri(“/XConsole;component/Images/Type_SYSTEM.png”, UriKind.Relative); return new System.Windows.Media.Imaging.BitmapImage(uri) { CacheOption = […]

设置图像源

我正在尝试将图像源设置为来自我的计算机(而不是资产)。 这就是我试图这样做的方式: Uri uri = new Uri(@”D:\Riot Games\about.png”, UriKind.Absolute); ImageSource imgSource = new BitmapImage(uri); this.image1.Source = imgSource; 我尝试了几乎所有我能在网上找到的东西,但似乎没什么用。 知道为什么吗? XAML: