bool TryGetUriProperty(object imageSource, out AbstractProperty uriProperty)
        {
            uriProperty = null;
            if (imageSource == null)
            {
                return(false);
            }

            MultiImageSource miSource = imageSource as MultiImageSource;

            if (miSource != null)
            {
                uriProperty = miSource.UriSourceProperty;
                return(true);
            }

            BitmapImageSource bSource = imageSource as BitmapImageSource;

            if (bSource != null)
            {
                uriProperty = bSource.UriSourceProperty;
                return(true);
            }
            return(false);
        }
        public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager)
        {
            base.DeepCopy(source, copyManager);
            Detach();
            BitmapImageSource b = (BitmapImageSource)source;

            UriSource          = b.UriSource;
            DecodePixelWidth   = b.DecodePixelWidth;
            DecodePixelHeight  = b.DecodePixelHeight;
            Thumbnail          = b.Thumbnail;
            ThumbnailDimension = b.ThumbnailDimension;
            BorderColor        = b.BorderColor;

            Attach();
            FreeData();
        }
示例#3
0
    /// <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.
            bmi.ThumbnailDimension = (int)Math.Max(Width, Height);
          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 = uriSource;
      }
      return null;
    }
示例#4
0
    /// <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)
    {
      ImageSource result;
      bool thumbnail = allowThumbs && Thumbnail;

      _invalidateImageSourceOnResize = false;
      if (source is MediaItem)
      {
        result = MediaItemsHelper.CreateThumbnailImageSource((MediaItem) source, (int) Math.Max(Width, Height));
        _invalidateImageSourceOnResize = true;
      }
      else if (source is IResourceLocator)
      {
        IResourceLocator resourceLocator = (IResourceLocator) source;
        result = new ResourceAccessorTextureImageSource(resourceLocator.CreateAccessor(), RightAngledRotation.Zero);
      }
      else
        result = source as ImageSource;
      if (result == null)
      {
        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.
              bmi.ThumbnailDimension = (int) Math.Max(Width, Height);
            result = bmi;
          }
          // TODO: More image types
          else
          {
            if (_formerWarnURI != uriSource)
            {
              ServiceRegistration.Get<ILogger>().Warn("Image: Image source '{0}' is not supported", uriSource);
              // Remember if we already wrote a warning to the log to avoid log flooding
              _formerWarnURI = uriSource;
            }
          }
        }
      }
      return result;
    }