Ejemplo n.º 1
0
        public static Image cachedNetworkImage(
            string src,
            Key key                              = null,
            float scale                          = 1.0f,
            float?width                          = null,
            float?height                         = null,
            Color color                          = null,
            BlendMode colorBlendMode             = BlendMode.srcIn,
            BoxFit?fit                           = null,
            Alignment alignment                  = null,
            ImageRepeat repeat                   = ImageRepeat.noRepeat,
            Rect centerSlice                     = null,
            bool gaplessPlayback                 = false,
            FilterMode filterMode                = FilterMode.Bilinear,
            IDictionary <string, string> headers = null
            )
        {
            var imageProvider = new CachedNetworkImageProvider(url: src, scale: scale, headers: headers);

            return(new Image(
                       key: key,
                       image: imageProvider,
                       width: width,
                       height: height,
                       color: color,
                       colorBlendMode: colorBlendMode,
                       fit: fit,
                       alignment: alignment,
                       repeat: repeat,
                       centerSlice: centerSlice,
                       gaplessPlayback: gaplessPlayback,
                       filterMode: filterMode
                       ));
        }
Ejemplo n.º 2
0
 public FadeInImage(
     ImageProvider placeholder,
     ImageProvider image,
     TimeSpan? fadeOutDuration = null,
     Curve fadeOutCurve = null,
     TimeSpan? fadeInDuration = null,
     Curve fadeInCurve = null,
     float? width = null,
     float? height = null,
     BoxFit? fit = null,
     Alignment alignment = null,
     ImageRepeat repeat = ImageRepeat.noRepeat,
     Key key = null
 ) : base(key) {
     D.assert(placeholder != null);
     D.assert(image != null);
     D.assert(fadeOutDuration != null);
     D.assert(fadeOutCurve != null);
     D.assert(fadeInDuration != null);
     D.assert(fadeInCurve != null);
     D.assert(alignment != null);
     this.placeholder = placeholder;
     this.image = image;
     this.width = width;
     this.height = height;
     this.fit = fit;
     this.fadeOutDuration = fadeOutDuration ?? TimeSpan.FromMilliseconds(300);
     this.fadeOutCurve = fadeOutCurve ?? Curves.easeOut;
     this.fadeInDuration = fadeInDuration ?? TimeSpan.FromMilliseconds(700);
     this.fadeInCurve = fadeInCurve ?? Curves.easeIn;
     this.alignment = alignment ?? Alignment.center;
     this.repeat = repeat;
 }
Ejemplo n.º 3
0
        public static Image file(
            string file,
            Key key                  = null,
            float scale              = 1.0f,
            float?width              = null,
            float?height             = null,
            Color color              = null,
            BlendMode colorBlendMode = BlendMode.srcIn,
            BoxFit?fit               = null,
            Alignment alignment      = null,
            ImageRepeat repeat       = ImageRepeat.noRepeat,
            Rect centerSlice         = null,
            bool gaplessPlayback     = false,
            FilterMode filterMode    = FilterMode.Bilinear
            )
        {
            var fileImage = new FileImage(file, scale);

            return(new Image(
                       key,
                       fileImage,
                       width,
                       height,
                       color,
                       colorBlendMode,
                       fit,
                       alignment,
                       repeat,
                       centerSlice,
                       gaplessPlayback,
                       filterMode
                       ));
        }
Ejemplo n.º 4
0
 public CachedNetworkImage(
     string src,
     Widget placeholder       = null,
     float scale              = 1.0f,
     float?width              = null,
     float?height             = null,
     Color color              = null,
     BlendMode colorBlendMode = BlendMode.modulate,
     BoxFit?fit            = null,
     Alignment alignment   = null,
     ImageRepeat repeat    = ImageRepeat.noRepeat,
     Rect centerSlice      = null,
     FilterMode filterMode = FilterMode.Bilinear,
     IDictionary <string, string> headers = null,
     OnImageResolved onImageResolved      = null,
     Key key = null
     ) : base(key: key)
 {
     this.src             = src;
     this.placeholder     = placeholder;
     this.scale           = scale;
     this.width           = width;
     this.height          = height;
     this.color           = color;
     this.colorBlendMode  = colorBlendMode;
     this.fit             = fit;
     this.alignment       = alignment;
     this.repeat          = repeat;
     this.centerSlice     = centerSlice;
     this.filterMode      = filterMode;
     this.headers         = headers;
     this.onImageResolved = onImageResolved;
 }
Ejemplo n.º 5
0
        public static Image network(
            string src,
            Key key                              = null,
            float scale                          = 1.0f,
            float?width                          = null,
            float?height                         = null,
            Color color                          = null,
            BlendMode colorBlendMode             = BlendMode.srcIn,
            BoxFit?fit                           = null,
            Alignment alignment                  = null,
            ImageRepeat repeat                   = ImageRepeat.noRepeat,
            Rect centerSlice                     = null,
            bool gaplessPlayback                 = false,
            FilterMode filterMode                = FilterMode.Point,
            IDictionary <string, string> headers = null
            )
        {
            var networkImage = new NetworkImage(src, scale, headers);

            return(new Image(
                       key,
                       networkImage,
                       width,
                       height,
                       color,
                       colorBlendMode,
                       fit,
                       alignment,
                       repeat,
                       centerSlice,
                       gaplessPlayback,
                       filterMode
                       ));
        }
Ejemplo n.º 6
0
 public RenderImage(
     Image image              = null,
     float?width              = null,
     float?height             = null,
     float scale              = 1.0f,
     Color color              = null,
     BlendMode colorBlendMode = BlendMode.srcIn,
     BoxFit?fit            = null,
     Alignment alignment   = null,
     ImageRepeat repeat    = ImageRepeat.noRepeat,
     Rect centerSlice      = null,
     bool invertColors     = false,
     FilterMode filterMode = FilterMode.Point
     )
 {
     this._image          = image;
     this._width          = width;
     this._height         = height;
     this._scale          = scale;
     this._color          = color;
     this._colorBlendMode = colorBlendMode;
     this._fit            = fit;
     this._repeat         = repeat;
     this._centerSlice    = centerSlice;
     this._alignment      = alignment ?? Alignment.center;
     this._invertColors   = invertColors;
     this._filterMode     = filterMode;
 }
Ejemplo n.º 7
0
 public Image(
     Key key                  = null,
     ImageProvider image      = null,
     float?width              = null,
     float?height             = null,
     Color color              = null,
     BlendMode colorBlendMode = BlendMode.srcIn,
     BoxFit?fit               = null,
     Alignment alignment      = null,
     ImageRepeat repeat       = ImageRepeat.noRepeat,
     Rect centerSlice         = null,
     bool gaplessPlayback     = false,
     FilterMode filterMode    = FilterMode.Point
     ) : base(key)
 {
     D.assert(image != null);
     this.image           = image;
     this.width           = width;
     this.height          = height;
     this.color           = color;
     this.colorBlendMode  = colorBlendMode;
     this.fit             = fit;
     this.alignment       = alignment ?? Alignment.center;
     this.repeat          = repeat;
     this.centerSlice     = centerSlice;
     this.gaplessPlayback = gaplessPlayback;
     this.filterMode      = filterMode;
 }
Ejemplo n.º 8
0
        public static Image memory(
            byte[] bytes,
            Key key                  = null,
            float scale              = 1.0f,
            float?width              = null,
            float?height             = null,
            Color color              = null,
            BlendMode colorBlendMode = BlendMode.srcIn,
            BoxFit?fit               = null,
            Alignment alignment      = null,
            ImageRepeat repeat       = ImageRepeat.noRepeat,
            Rect centerSlice         = null,
            bool gaplessPlayback     = false,
            FilterMode filterMode    = FilterMode.Point
            )
        {
            var memoryImage = new MemoryImage(bytes, scale);

            return(new Image(
                       key,
                       memoryImage,
                       width,
                       height,
                       color,
                       colorBlendMode,
                       fit,
                       alignment,
                       repeat,
                       centerSlice,
                       gaplessPlayback,
                       filterMode
                       ));
        }
Ejemplo n.º 9
0
 public RenderImage(
     Image image              = null,
     float?width              = null,
     float?height             = null,
     float scale              = 1.0f,
     Color color              = null,
     BlendMode colorBlendMode = BlendMode.srcIn,
     BoxFit?fit = null,
     AlignmentGeometry alignment = null,
     ImageRepeat repeat          = ImageRepeat.noRepeat,
     Rect centerSlice            = null,
     bool matchTextDirection     = false,
     TextDirection?textDirection = null,
     bool invertColors           = false,
     FilterQuality filterQuality = FilterQuality.low
     )
 {
     D.assert(alignment != null);
     _image              = image;
     _width              = width;
     _height             = height;
     _scale              = scale;
     _color              = color;
     _colorBlendMode     = colorBlendMode;
     _fit                = fit;
     _repeat             = repeat;
     _centerSlice        = centerSlice;
     _alignment          = alignment ?? Alignment.center;
     _invertColors       = invertColors;
     _filterQuality      = filterQuality;
     _textDirection      = textDirection;
     _matchTextDirection = matchTextDirection;
     _updateColorFilter();
 }
Ejemplo n.º 10
0
 public ImageWithProgress(
     ImageProvider image,
     Func <float> progress,
     BoxFit?fit = null)
 {
     this.image    = image;
     this.progress = progress;
     this.fit      = fit;
 }
Ejemplo n.º 11
0
        public static FadeInImage assetNetwork(
            string placeholder,
            string image,
            ImageErrorWidgetBuilder placeholderErrorBuilder = null,
            ImageErrorWidgetBuilder imageErrorBuilder       = null,
            AssetBundle bundle       = null,
            float?placeholderScale   = null,
            float imageScale         = 1.0f,
            TimeSpan?fadeOutDuration = null,
            Curve fadeOutCurve       = null,
            TimeSpan?fadeInDuration  = null,
            Curve fadeInCurve        = null,
            float?width  = null,
            float?height = null,
            BoxFit?fit   = null,
            AlignmentGeometry alignment = null,
            ImageRepeat repeat          = ImageRepeat.noRepeat,
            bool matchTextDirection     = false,
            Key key = null,
            int?placeholderCacheWidth  = null,
            int?placeholderCacheHeight = null,
            int?imageCacheWidth        = null,
            int?imageCacheHeight       = null
            )
        {
            fadeOutDuration = fadeOutDuration ?? new TimeSpan(0, 0, 0, 0, 300);
            fadeOutCurve    = fadeOutCurve ?? Curves.easeOut;
            fadeInDuration  = fadeInDuration ?? new TimeSpan(0, 0, 0, 0, 700);
            fadeInCurve     = Curves.easeIn;
            alignment       = alignment ?? Alignment.center;
            var holder       = placeholderScale ?? 1.0f;
            var _placeholder = placeholderScale != null
                ? ResizeImage.resizeIfNeeded(placeholderCacheWidth, placeholderCacheHeight,
                                             new ExactAssetImage(placeholder, bundle : bundle, scale : holder))
                               : ResizeImage.resizeIfNeeded(placeholderCacheWidth, placeholderCacheHeight,
                                                            new AssetImage(placeholder, bundle : bundle));

            return(new FadeInImage(
                       placeholder: _placeholder,
                       placeholderErrorBuilder: placeholderErrorBuilder,
                       image: ResizeImage.resizeIfNeeded(imageCacheWidth, imageCacheHeight, new NetworkImage(image, scale: imageScale)),
                       imageErrorBuilder: imageErrorBuilder,
                       fadeOutDuration: fadeOutDuration,
                       fadeOutCurve: fadeOutCurve,
                       fadeInDuration: fadeInDuration,
                       fadeInCurve: fadeInCurve,
                       width: width, height: height,
                       fit: fit,
                       alignment: alignment,
                       repeat: repeat,
                       matchTextDirection: matchTextDirection,
                       key: key
                       ));
        }
Ejemplo n.º 12
0
        public static FadeInImage memoryNetwork(
            byte[] placeholder,
            string image,
            Key key = null,
            ImageErrorWidgetBuilder placeholderErrorBuilder = null,
            ImageErrorWidgetBuilder imageErrorBuilder       = null,
            float placeholderScale   = 1.0f,
            float imageScale         = 1.0f,
            TimeSpan?fadeOutDuration = null,
            Curve fadeOutCurve       = null,
            TimeSpan?fadeInDuration  = null,
            Curve fadeInCurve        = null,
            float?width  = null,
            float?height = null,
            BoxFit?fit   = null,
            AlignmentGeometry alignment = null,
            ImageRepeat repeat          = ImageRepeat.noRepeat,
            bool matchTextDirection     = false,
            int?placeholderCacheWidth   = null,
            int?placeholderCacheHeight  = null,
            int?imageCacheWidth         = null,
            int?imageCacheHeight        = null
            )
        {
            alignment       = alignment ?? Alignment.center;
            fadeOutDuration = fadeOutDuration ?? TimeSpan.FromMilliseconds(300);
            fadeOutCurve    = fadeOutCurve ?? Curves.easeOut;
            fadeInDuration  = fadeInDuration ?? TimeSpan.FromMilliseconds(700);
            fadeInCurve     = fadeInCurve ?? Curves.easeIn;
            ImageProvider memoryImage  = new MemoryImage(placeholder, placeholderScale);
            ImageProvider networkImage = new NetworkImage(image, imageScale);

            //placeholder = ResizeImage.resizeIfNeeded(placeholderCacheWidth, placeholderCacheHeight, memoryImage);
            //image = ResizeImage.resizeIfNeeded(imageCacheWidth, imageCacheHeight, networkImage);
            return(new FadeInImage(
                       placeholder: ResizeImage.resizeIfNeeded(placeholderCacheWidth, placeholderCacheHeight, memoryImage),
                       placeholderErrorBuilder: placeholderErrorBuilder,
                       image: ResizeImage.resizeIfNeeded(imageCacheWidth, imageCacheHeight, networkImage),
                       imageErrorBuilder: imageErrorBuilder,
                       fadeOutDuration: fadeOutDuration,
                       fadeOutCurve: fadeOutCurve,
                       fadeInDuration: fadeInDuration,
                       fadeInCurve: fadeInCurve,
                       width: width, height: height,
                       fit: fit,
                       alignment: alignment,
                       repeat: repeat,
                       matchTextDirection: matchTextDirection,
                       key: key
                       ));
        }
Ejemplo n.º 13
0
        public static Image asset(
            string name,
            Key key                              = null,
            AssetBundle bundle                   = null,
            ImageFrameBuilder frameBuilder       = null,
            ImageErrorWidgetBuilder errorBuilder = null,
            float?scale                          = null,
            float?width                          = null,
            float?height                         = null,
            Color color                          = null,
            BlendMode colorBlendMode             = BlendMode.srcIn,
            BoxFit?fit                           = null,
            Alignment alignment                  = null,
            ImageRepeat repeat                   = ImageRepeat.noRepeat,
            Rect centerSlice                     = null,
            bool matchTextDirection              = false,
            bool gaplessPlayback                 = false,
            string package                       = null,
            FilterQuality filterQuality          = FilterQuality.low,
            int?cacheWidth                       = default,
            int?cacheHeight                      = null
            )
        {
            var _scale = scale ?? 1.0f;
            var _image = scale != null
                ? (AssetBundleImageProvider) new ExactAssetImage(assetName: name, bundle: bundle, scale: _scale)
                : new AssetImage(assetName: name, bundle: bundle);
            var _Image = ResizeImage.resizeIfNeeded(cacheWidth: cacheWidth, cacheHeight: cacheHeight, provider: _image);

            return(new Image(
                       key: key,
                       image: _Image,
                       frameBuilder: frameBuilder,
                       null,
                       errorBuilder: errorBuilder,
                       width: width,
                       height: height,
                       color: color,
                       colorBlendMode: colorBlendMode,
                       fit: fit,
                       alignment: alignment,
                       repeat: repeat,
                       centerSlice: centerSlice,
                       matchTextDirection: matchTextDirection,
                       gaplessPlayback: gaplessPlayback,
                       filterQuality: filterQuality
                       ));
        }
Ejemplo n.º 14
0
 public PlaceholderImage(
     string imageUrl,
     float?width        = null,
     float?height       = null,
     float?borderRadius = null,
     BoxFit?fit         = null,
     Key key            = null
     ) : base(key)
 {
     D.assert(imageUrl != null);
     D.assert(borderRadius == null || borderRadius >= 0);
     this.imageUrl     = imageUrl;
     this.width        = width;
     this.height       = height;
     this.borderRadius = borderRadius;
     this.fit          = fit;
 }
Ejemplo n.º 15
0
 public DecorationImage(
     ImageProvider image     = null,
     ColorFilter colorFilter = null,
     BoxFit?fit          = null,
     Alignment alignment = null,
     Rect centerSlice    = null,
     ImageRepeat repeat  = ImageRepeat.noRepeat
     )
 {
     D.assert(image != null);
     this.image       = image;
     this.colorFilter = colorFilter;
     this.fit         = fit;
     this.alignment   = alignment ?? Alignment.center;
     this.centerSlice = centerSlice;
     this.repeat      = repeat;
 }
Ejemplo n.º 16
0
        public static Image network(
            string src,
            Key key     = null,
            float scale = 1.0f,
            ImageFrameBuilder frameBuilder       = null,
            ImageLoadingBuilder loadingBuilder   = null,
            ImageErrorWidgetBuilder errorBuilder = null,
            float?width              = null,
            float?height             = null,
            Color color              = null,
            BlendMode colorBlendMode = BlendMode.srcIn,
            BoxFit?fit = null,
            AlignmentGeometry alignment          = null,
            ImageRepeat repeat                   = ImageRepeat.noRepeat,
            Rect centerSlice                     = null,
            bool gaplessPlayback                 = false,
            bool matchTextDirection              = false,
            FilterQuality filterQuality          = FilterQuality.low,
            IDictionary <string, string> headers = null,
            int?cacheWidth  = null,
            int?cacheHeight = null
            )
        {
            var image = ResizeImage.resizeIfNeeded(cacheWidth: cacheWidth, cacheHeight: cacheHeight,
                                                   new NetworkImage(url: src, scale: scale, headers: headers));

            return(new Image(
                       key: key,
                       image: image,
                       frameBuilder: frameBuilder,
                       loadingBuilder: loadingBuilder,
                       errorBuilder: errorBuilder,
                       width: width,
                       height: height,
                       color: color,
                       colorBlendMode: colorBlendMode,
                       fit: fit,
                       alignment: alignment,
                       repeat: repeat,
                       centerSlice: centerSlice,
                       matchTextDirection: matchTextDirection,
                       gaplessPlayback: gaplessPlayback,
                       filterQuality: filterQuality
                       ));
        }
Ejemplo n.º 17
0
        public static FadeInImage assetNetwork(
            string placeholder,
            string image,
            AssetBundle bundle       = null,
            float?placeholderScale   = null,
            float imageScale         = 1.0f,
            TimeSpan?fadeOutDuration = null,
            Curve fadeOutCurve       = null,
            TimeSpan?fadeInDuration  = null,
            Curve fadeInCurve        = null,
            float?width         = null,
            float?height        = null,
            BoxFit?fit          = null,
            Alignment alignment = null,
            ImageRepeat repeat  = ImageRepeat.noRepeat,
            Key key             = null
            )
        {
            D.assert(placeholder != null);
            D.assert(image != null);
            D.assert(fadeOutDuration != null);
            D.assert(fadeOutCurve != null);
            D.assert(fadeInDuration != null);
            D.assert(fadeInCurve != null);
            D.assert(alignment != null);
            var imageProvider = placeholderScale != null
                ? new ExactAssetImage(placeholder, bundle: bundle, scale: placeholderScale ?? 1.0f)
                : (ImageProvider) new AssetImage(placeholder, bundle: bundle);

            var networkImage = new NetworkImage(image, imageScale);

            return(new FadeInImage(
                       imageProvider,
                       networkImage,
                       fadeOutDuration,
                       fadeOutCurve,
                       fadeInDuration,
                       fadeInCurve,
                       width, height,
                       fit,
                       alignment,
                       repeat,
                       key
                       ));
        }
Ejemplo n.º 18
0
        public static Image memory(
            byte[] bytes,
            Key key     = null,
            float scale = 1.0f,
            ImageFrameBuilder frameBuilder       = null,
            ImageErrorWidgetBuilder errorBuilder = null,
            float?width              = null,
            float?height             = null,
            Color color              = null,
            BlendMode colorBlendMode = BlendMode.srcIn,
            BoxFit?fit                  = null,
            Alignment alignment         = null,
            ImageRepeat repeat          = ImageRepeat.noRepeat,
            Rect centerSlice            = null,
            bool matchTextDirection     = false,
            bool gaplessPlayback        = false,
            FilterQuality filterQuality = FilterQuality.low,
            int?cacheWidth              = default,
            int?cacheHeight             = null
            )
        {
            // ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, MemoryImage(bytes, scale: scale));
            var memoryImage = new MemoryImage(bytes: bytes, scale: scale);

            return(new Image(
                       key: key,
                       ResizeImage.resizeIfNeeded(cacheWidth: cacheWidth, cacheHeight: cacheHeight,
                                                  new MemoryImage(bytes: bytes, scale: scale)),
                       frameBuilder: frameBuilder,
                       null,
                       errorBuilder: errorBuilder,
                       width: width,
                       height: height,
                       color: color,
                       colorBlendMode: colorBlendMode,
                       fit: fit,
                       alignment: alignment,
                       repeat: repeat,
                       centerSlice: centerSlice,
                       matchTextDirection: matchTextDirection,
                       gaplessPlayback: gaplessPlayback,
                       filterQuality: filterQuality
                       ));
        }
Ejemplo n.º 19
0
        public static FadeInImage memoryNetwork(
            byte[] placeholder,
            string image,
            float placeholderScale   = 1.0f,
            float imageScale         = 1.0f,
            TimeSpan?fadeOutDuration = null,
            Curve fadeOutCurve       = null,
            TimeSpan?fadeInDuration  = null,
            Curve fadeInCurve        = null,
            float?width         = null,
            float?height        = null,
            BoxFit?fit          = null,
            Alignment alignment = null,
            ImageRepeat repeat  = ImageRepeat.noRepeat,
            Key key             = null
            )
        {
            D.assert(placeholder != null);
            D.assert(image != null);
            D.assert(fadeOutDuration != null);
            D.assert(fadeOutCurve != null);
            D.assert(fadeInDuration != null);
            D.assert(fadeInCurve != null);
            D.assert(alignment != null);
            var memoryImage  = new MemoryImage(placeholder, placeholderScale);
            var networkImage = new NetworkImage(image, imageScale);

            return(new FadeInImage(
                       memoryImage,
                       networkImage,
                       fadeOutDuration,
                       fadeOutCurve,
                       fadeInDuration,
                       fadeInCurve,
                       width, height,
                       fit,
                       alignment,
                       repeat,
                       key
                       ));
        }
Ejemplo n.º 20
0
 public PlaceholderImage(
     string imageUrl,
     float?width                = null,
     float?height               = null,
     float?borderRadius         = null,
     BoxFit?fit                 = null,
     bool useCachedNetworkImage = false,
     Color color                = null,
     Key key = null
     ) : base(key: key)
 {
     D.assert(imageUrl != null);
     D.assert(borderRadius == null || borderRadius >= 0);
     this.imageUrl              = imageUrl;
     this.width                 = width;
     this.height                = height;
     this.borderRadius          = borderRadius;
     this.fit                   = fit;
     this.useCachedNetworkImage = useCachedNetworkImage;
     this.color                 = color ?? CColors.LoadingGrey;
 }
Ejemplo n.º 21
0
 public DecorationImage(
     ImageProvider image        = null,
     ImageErrorListener onError = null,
     ColorFilter colorFilter    = null,
     BoxFit?fit = null,
     AlignmentGeometry alignment = null,
     Rect centerSlice            = null,
     ImageRepeat repeat          = ImageRepeat.noRepeat,
     bool matchTextDirection     = false
     )
 {
     D.assert(image != null);
     this.image              = image;
     this.onError            = onError;
     this.colorFilter        = colorFilter;
     this.fit                = fit;
     this.alignment          = alignment ?? Alignment.center;
     this.centerSlice        = centerSlice;
     this.repeat             = repeat;
     this.matchTextDirection = matchTextDirection;
 }
Ejemplo n.º 22
0
        public static Ink image(
            Key key = null,
            EdgeInsetsGeometry padding      = null,
            ImageProvider image             = null,
            ImageErrorListener onImageError = null,
            ColorFilter colorFilter         = null,
            BoxFit?fit = null,
            AlignmentGeometry alignment = null,
            Rect centerSlice            = null,
            ImageRepeat repeat          = ImageRepeat.noRepeat,
            float?width  = null,
            float?height = null,
            Widget child = null
            )
        {
            D.assert(padding == null || padding.isNonNegative);
            D.assert(image != null);

            alignment = alignment ?? Alignment.center;
            Decoration decoration = new BoxDecoration(
                image: new DecorationImage(
                    image: image,
                    onError: onImageError,
                    colorFilter: colorFilter,
                    fit: fit,
                    alignment: alignment,
                    centerSlice: centerSlice,
                    repeat: repeat)
                );

            return(new Ink(
                       key: key,
                       padding: padding,
                       decoration: decoration,
                       width: width,
                       height: height,
                       child: child));
        }
Ejemplo n.º 23
0
        public static Image asset(
            string name,
            Key key                  = null,
            AssetBundle bundle       = null,
            float?scale              = null,
            float?width              = null,
            float?height             = null,
            Color color              = null,
            BlendMode colorBlendMode = BlendMode.srcIn,
            BoxFit?fit               = null,
            Alignment alignment      = null,
            ImageRepeat repeat       = ImageRepeat.noRepeat,
            Rect centerSlice         = null,
            bool gaplessPlayback     = false,
            FilterMode filterMode    = FilterMode.Point
            )
        {
            var image = scale != null
                ? (AssetBundleImageProvider) new ExactAssetImage(name, bundle: bundle, scale: scale.Value)
                : new AssetImage(name, bundle: bundle);

            return(new Image(
                       key,
                       image,
                       width,
                       height,
                       color,
                       colorBlendMode,
                       fit,
                       alignment,
                       repeat,
                       centerSlice,
                       gaplessPlayback,
                       filterMode
                       ));
        }
Ejemplo n.º 24
0
 public Image(
     Key key                              = null,
     ImageProvider image                  = null,
     ImageFrameBuilder frameBuilder       = null,
     ImageLoadingBuilder loadingBuilder   = null,
     ImageErrorWidgetBuilder errorBuilder = null,
     float?width                          = null,
     float?height                         = null,
     Color color                          = null,
     BlendMode colorBlendMode             = BlendMode.srcIn,
     BoxFit?fit                           = null,
     AlignmentGeometry alignment          = null,
     ImageRepeat repeat                   = ImageRepeat.noRepeat,
     Rect centerSlice                     = null,
     bool matchTextDirection              = false,
     bool gaplessPlayback                 = false,
     FilterQuality filterQuality          = FilterQuality.low
     ) : base(key: key)
 {
     D.assert(image != null);
     this.image              = image;
     this.frameBuilder       = frameBuilder;
     this.loadingBuilder     = loadingBuilder;
     this.errorBuilder       = errorBuilder;
     this.width              = width;
     this.height             = height;
     this.color              = color;
     this.colorBlendMode     = colorBlendMode;
     this.fit                = fit;
     this.alignment          = alignment ?? Alignment.center;
     this.repeat             = repeat;
     this.centerSlice        = centerSlice;
     this.gaplessPlayback    = gaplessPlayback;
     this.filterQuality      = filterQuality;
     this.matchTextDirection = matchTextDirection;
 }
Ejemplo n.º 25
0
        public static void paintImage(
            Canvas canvas               = null,
            Rect rect                   = null,
            Image image                 = null,
            float scale                 = 1.0f,
            ColorFilter colorFilter     = null,
            BoxFit?fit                  = null,
            Alignment alignment         = null,
            Rect centerSlice            = null,
            ImageRepeat repeat          = ImageRepeat.noRepeat,
            bool flipHorizontally       = false,
            bool invertColors           = false,
            FilterQuality filterQuality = FilterQuality.low
            )
        {
            D.assert(canvas != null);
            D.assert(rect != null);
            D.assert(image != null);
            alignment = alignment ?? Alignment.center;

            if (rect.isEmpty)
            {
                return;
            }

            Size   outputSize  = rect.size;
            Size   inputSize   = new Size(image.width, image.height);
            Offset sliceBorder = null;

            if (centerSlice != null)
            {
                sliceBorder = new Offset(
                    centerSlice.left + inputSize.width - centerSlice.right,
                    centerSlice.top + inputSize.height - centerSlice.bottom
                    );
                outputSize -= sliceBorder;
                inputSize  -= sliceBorder;
            }

            fit = fit ?? (centerSlice == null ? BoxFit.scaleDown : BoxFit.fill);
            D.assert(centerSlice == null || (fit != BoxFit.none && fit != BoxFit.cover),
                     () => $"centerSlice was used with a BoxFit {fit} that is not supported.");
            FittedSizes fittedSizes     = FittedSizes.applyBoxFit(fit.Value, inputSize / scale, outputSize);
            Size        sourceSize      = fittedSizes.source * scale;
            Size        destinationSize = fittedSizes.destination;

            if (centerSlice != null)
            {
                outputSize      += sliceBorder;
                destinationSize += sliceBorder;
                D.assert(sourceSize == inputSize,
                         () =>
                         $"centerSlice was used with a BoxFit {fit} that does not guarantee that the image is fully visible.");
            }

            if (repeat != ImageRepeat.noRepeat && destinationSize == outputSize)
            {
                repeat = ImageRepeat.noRepeat;
            }

            Paint paint = new Paint();

            if (colorFilter != null)
            {
                paint.colorFilter = colorFilter;
            }

            if (sourceSize != destinationSize)
            {
                paint.filterQuality = filterQuality;
            }

            paint.invertColors = invertColors;

            float  halfWidthDelta  = (outputSize.width - destinationSize.width) / 2.0f;
            float  halfHeightDelta = (outputSize.height - destinationSize.height) / 2.0f;
            float  dx = halfWidthDelta + (flipHorizontally ? -alignment.x : alignment.x) * halfWidthDelta;
            float  dy = halfHeightDelta + alignment.y * halfHeightDelta;
            Offset destinationPosition = rect.topLeft.translate(dx, dy);
            Rect   destinationRect     = destinationPosition & destinationSize;
            bool   needSave            = repeat != ImageRepeat.noRepeat || flipHorizontally;

            if (needSave)
            {
                canvas.save();
            }

            if (flipHorizontally)
            {
                float dxInside = -(rect.left + rect.width / 2.0f);
                canvas.translate(-dxInside, 0.0f);
                canvas.scale(-1.0f, 1.0f);
                canvas.translate(dxInside, 0.0f);
            }

            if (repeat != ImageRepeat.noRepeat)
            {
                canvas.clipRect(rect);
            }

            if (centerSlice == null)
            {
                Rect sourceRect = alignment.inscribe(
                    sourceSize, Offset.zero & inputSize
                    );
                if (repeat == ImageRepeat.noRepeat)
                {
                    canvas.drawImageRect(image, sourceRect, destinationRect, paint);
                }
                else
                {
                    foreach (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat))
                    {
                        canvas.drawImageRect(image, sourceRect, tileRect, paint);
                    }
                }
            }
            else
            {
                if (repeat == ImageRepeat.noRepeat)
                {
                    canvas.drawImageNine(image, centerSlice, destinationRect, paint);
                }
                else
                {
                    foreach (Rect tileRect in _generateImageTileRects(rect, destinationRect, repeat))
                    {
                        canvas.drawImageNine(image, centerSlice, tileRect, paint);
                    }
                }
            }

            if (needSave)
            {
                canvas.restore();
            }
        }