public static ImageSource CreateFanArtImageSource(object source, int width, int height) { MediaItem mediaItem = source as MediaItem; if (mediaItem == null) { return(null); } // Use the ThumbnailAspect as fallback for non-ML imported MediaItems if (mediaItem.MediaItemId == Guid.Empty) { return(ImageSourceFactory.CreateMediaItemThumbnailAspectSource(source, width, height)); } string mediaType = FanArtMediaTypes.Undefined; // Special handling for ImageThumbs that might require rotation if (mediaItem.Aspects.ContainsKey(ImageAspect.ASPECT_ID)) { mediaType = FanArtMediaTypes.Image; } FanArtImageSource fanArtImageSource = new FanArtImageSource { FanArtMediaType = mediaType, FanArtType = FanArtTypes.Thumbnail, MaxWidth = MAX_SIZE_THUMBS, MaxHeight = MAX_SIZE_THUMBS, // Order matters here: if all arguments are complete, download will start. We control the start time by setting FanArtName after all required properties are set FanArtName = mediaItem.MediaItemId.ToString() }; return(fanArtImageSource); }
string GetUri(object imageSource) { if (imageSource == null) { return(null); } string uri = imageSource as string; if (uri != null) { return(uri); } ImageSource convertedSource; if (!ImageSourceFactory.TryCreateImageSource(imageSource, 0, 0, out convertedSource)) { return(null); } AbstractProperty uriProperty; if (TryGetUriProperty(convertedSource, out uriProperty)) { return(uriProperty.GetValue() as string); } ServiceRegistration.Get <ILogger>().Warn("ImageSourceWrapper: Unsupported ImageSource type '{0}'", imageSource.GetType()); return(null); }
private void AddFile(List <IImageSource> textures, string item) { IImageSource source = ImageSourceFactory.CreateSourceFromFile(item); textures.Add(source); OnTextureLoaded(source.CurrentTexture); }
private ImageSource GetImageFromResource(string name) { if (ImageSourceFactory == null) { return(Views.ImageSourceFactory.Instance.GetImageSource(name)); } return(ImageSourceFactory.GetImage(name)); }
/// <summary> /// Loads an ImageSource and allows control of thumbnail use. /// Morpheus_xx, 2011-12-13: For fallback sources no thumbnails should be used, because ALL thumbs are created as JPG. This currenly causes an issue: /// Source -> no thumbnail created -> FallbackSource (PNG) -> creates a JPG thumbnail, so Alpha-Channel of FallbackSource is lost. /// TODO: Image class and thumbnail handling should be refactored to allow more control about image formats and thumbs usage. /// </summary> /// <param name="source">Source</param> /// <param name="allowThumbs">True to allow building a thumbnail of given source</param> /// <returns>ImageSource or null</returns> protected ImageSource LoadImageSource(object source, bool allowThumbs) { if (source == null) { return(null); } bool thumbnail = allowThumbs && Thumbnail; ImageSource imageSource; if (ImageSourceFactory.TryCreateImageSource(source, (int)Width, (int)Height, out imageSource)) { return(imageSource); } string uriSource = source as string; if (!string.IsNullOrEmpty(uriSource)) { // Remember to adapt list of supported extensions for image player plugin... if (IsValidSource(uriSource)) { BitmapImageSource bmi = new BitmapImageSource { UriSource = uriSource, Thumbnail = thumbnail }; if (thumbnail) { // Set the requested thumbnail dimension, to use the best matching format. // Note: Math.Max returns NaN if one argument is NaN (which casts to int.MinValue), so the additional Max with 0 catches this bmi.ThumbnailDimension = Math.Max((int)Math.Max(Width, Height), 0); } return(bmi); } // TODO: More image types } string warnSource = source.ToString(); if (_formerWarnURI != warnSource) { if (!string.IsNullOrEmpty(warnSource)) { ServiceRegistration.Get <ILogger>().Warn("Image: Image source '{0}' is not supported", warnSource); } // Remember if we already wrote a warning to the log to avoid log flooding _formerWarnURI = warnSource; } return(null); }
public override void GetImages(GraphicsDevice graphicsDevice, List <IImageSource[]> textureSetListToAddTo, ref bool stop) { string debugInfoPictureFileName = ""; var tempTextures = new List <Texture2D[]>(); List <IImageSource> textures = new List <IImageSource>(); WebRequest request = System.Net.HttpWebRequest.Create(_urlToOpen); WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials; var response = (HttpWebResponse)request.GetResponse(); using (ZipArchive archive = new ZipArchive(response.GetResponseStream())) { foreach (var entry in archive.Entries) { if (stop) { return; } if (entry.Name.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || entry.Name.EndsWith(".png", StringComparison.OrdinalIgnoreCase) || entry.Name.EndsWith(".gif", StringComparison.OrdinalIgnoreCase)) { try { debugInfoPictureFileName = entry.FullName; using (Stream fileStream = entry.Open()) { IImageSource source = ImageSourceFactory.CreateSourceFromStream(fileStream, entry.FullName); textures.Add(source); OnTextureLoaded(source.CurrentTexture); } } catch (Exception ex) { Console.WriteLine(string.Format("Error loading image '{0}' from zipfile at URL '{1}'. Error is: {2}", debugInfoPictureFileName, _urlToOpen, ex.Message)); } } } } if (textures.Count > 0) { textureSetListToAddTo.Add(textures.ToArray()); } }
public void Activated(PluginRuntime pluginRuntime) { ImageSourceFactory.ReplaceCustomImageSource(ImageSourceFactory.CreateMediaItemThumbnailAspectSource, CreateFanArtImageSource); }
public override void GetImages(GraphicsDevice graphicsDevice, List <IImageSource[]> textureSetListToAddTo, ref bool stop) { List <string> zipFilesToOpen = new List <string>(); string debugInfoZipFileName = ""; string debugInfoPictureFileName = ""; try { string imageFolder = null; if (!string.IsNullOrWhiteSpace(_itemToOpen)) { if (Path.GetExtension(_itemToOpen) == ".zip") { zipFilesToOpen.Add(_itemToOpen); } else if (Directory.Exists(_itemToOpen)) { imageFolder = _itemToOpen; zipFilesToOpen = Directory.EnumerateFiles(imageFolder, "*.zip").ToList(); } } else { var runningFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); imageFolder = ConfigurationManager.AppSettings[AppSettingsKey] ?? runningFolder; if (Directory.Exists(imageFolder)) { zipFilesToOpen = Directory.EnumerateFiles(imageFolder, "*.zip").ToList(); } } var tempTextures = new List <Texture2D[]>(); for (int i = 0; i < zipFilesToOpen.Count(); i++) { List <IImageSource> textures = new List <IImageSource>(); debugInfoZipFileName = zipFilesToOpen[i]; using (ZipArchive archive = ZipFile.OpenRead(zipFilesToOpen[i])) { foreach (var entry in archive.Entries) { if (stop) { return; } if (entry.Name.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || entry.Name.EndsWith(".gng", StringComparison.OrdinalIgnoreCase) || entry.Name.EndsWith(".gif", StringComparison.OrdinalIgnoreCase)) { try { debugInfoPictureFileName = entry.FullName; using (Stream fileStream = entry.Open()) { IImageSource source = ImageSourceFactory.CreateSourceFromStream(fileStream, entry.FullName); textures.Add(source); OnTextureLoaded(source.CurrentTexture); } } catch (Exception ex) { Console.WriteLine(string.Format("Error loading image '{0}' from file '{1}'. Error is: {2}", debugInfoPictureFileName, debugInfoZipFileName, ex.Message)); } } } } if (textures.Count > 0) { textureSetListToAddTo.Add(textures.ToArray()); } } } catch (Exception ex) { throw new Exception(string.Format("Error loading image '{0}' from file '{1}'. Error is: {2}", debugInfoPictureFileName, debugInfoZipFileName, ex.ToString()), ex); } }
public override void GetImages(GraphicsDevice graphicsDevice, List <IImageSource[]> textureSetListToAddTo, ref bool stop) { List <string> imageFolders = new List <string>(); string debugInfoPictureFileName = ""; try { if (string.IsNullOrWhiteSpace(_imageSource)) { var _runningFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _imageSource = ConfigurationManager.AppSettings[AppSettingsKey] ?? _runningFolder; } if (Directory.Exists(_imageSource)) { imageFolders = Directory.GetDirectories(_imageSource).ToList(); imageFolders.Add(_imageSource); } else { List <IImageSource> textures = new List <IImageSource>(); AddFile(textures, _imageSource); textureSetListToAddTo.Add(textures.ToArray()); return; } for (int i = 0; i < imageFolders.Count; i++) { List <IImageSource> textures = new List <IImageSource>(); var files = Directory.GetFiles(imageFolders[i]).ToList(); foreach (var item in files) { Console.WriteLine(item); if (stop) { return; } try { if (ImageSourceFactory.IsValidImageSourceFile(item)) { AddFile(textures, item); } } catch (Exception ex) { Console.WriteLine(string.Format("Error loading image '{0}'. Error is: {1}", debugInfoPictureFileName, ex.Message)); } } if (textures.Count > 0) { textureSetListToAddTo.Add(textures.ToArray()); } } } catch (Exception ex) { throw new Exception(string.Format("Error loading image '{0}'. Error is: {1}", debugInfoPictureFileName, ex.ToString()), ex); } }