我正在尝试获取图像运行时并基于 ImageFilePathName 搜索图像。但是有可能图像不存在,但源路径仍然是使用空图像创建的。请任何人都可以建议如何检查源中是否包含有效的文件或图像。?谢谢
public object Convert(object value, Type targetType, object parameter, string culture)
{
StorageFolder installFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
string installFolderPath = installFolder.Path;
const string LOGO_KIND_SMALL = "Small";
ImageSource source;
string logoImageFilePathName;
try
{
int logoId = Int32.Parse((string)value);
logoImageFilePathName = string.Format("{0}\\{1}\\Logos\\Chan\\{2}\\{3:0000}.png", installFolderPath, "Assets", LOGO_KIND_SMALL, logoId);
try
{
source = new BitmapImage(new Uri(logoImageFilePathName));
return source;
}
catch(Exception ex)
{
Logger.LogError(ex.Message);
}
}
catch (Exception ex)
{
Logger.LogError(ex.Message);
}
logoImageFilePathName = string.Format("{0}\\{1}\\Logos\\Channels\\{2}\\{3}.png", installFolderPath, "Assets", LOGO_KIND_SMALL, "0000");
source = new BitmapImage(new Uri(logoImageFilePathName));
return source;
}
public object ConvertBack(object value, Type targetType, object parameter, string culture)
{
throw new NotSupportedException();
}