コード例 #1
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
                       ));
        }
コード例 #2
0
ファイル: ink_decoration.cs プロジェクト: wxFancer/UIWidgets
        public static Ink image(
            Key key                 = null,
            EdgeInsets padding      = null,
            ImageProvider image     = null,
            ColorFilter colorFilter = null,
            BoxFit?fit              = null,
            Alignment alignment     = null,
            Rect centerSlice        = null,
            ImageRepeat repeat      = ImageRepeat.noRepeat,
            double?width            = null,
            double?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,
                    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));
        }
コード例 #3
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;
 }
コード例 #4
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();
            }
        }
コード例 #5
0
		public PageImage(ImageFormat im, byte[] image, int w, int h)
		{
			Debug.Assert(im == ImageFormat.Jpeg || im == ImageFormat.Png || im == ImageFormat.Gif || im == ImageFormat.Wmf, 
							"PageImage only supports Jpeg, Gif and Png and WMF image formats (Thanks HYNE!).");
			imf = im;
			imageData = image;
			samplesW = w;
			samplesH = h;
			repeat = ImageRepeat.NoRepeat;
			sizing = ImageSizingEnum.AutoSize;
		}
コード例 #6
0
ファイル: Pages.cs プロジェクト: romeroyonatan/opendental
		public PageImage(ImageFormat im, byte[] image, int w, int h)
		{
			Debug.Assert(im == ImageFormat.Jpeg || im == ImageFormat.Png, 
							"PageImage only supports Jpeg and Png image formats.");
			imf = im;
			imageData = image;
			samplesW = w;
			samplesH = h;
			repeat = ImageRepeat.NoRepeat;
			sizing = ImageSizingEnum.AutoSize;
		}
コード例 #7
0
ファイル: StyleTemplate.cs プロジェクト: brhinescot/Loom
        /// <summary>
        ///     Converts an object into its XML representation.
        /// </summary>
        /// <param name="writer">
        ///     The <see cref="XmlWriter"></see> stream to which the object is
        ///     serialized.
        /// </param>
        void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            Dictionary <string, string> attributeValues = new Dictionary <string, string>();

            if (Font.Name != SystemFonts.DefaultFont.Name)
            {
                attributeValues.Add("fontName", Font.Name);
            }
            if (Font.Size != SystemFonts.DefaultFont.Size)
            {
                attributeValues.Add("fontSize", Font.Size.ToString(CultureInfo.InvariantCulture));
            }
            if (Font.Style != FontStyle.Regular)
            {
                attributeValues.Add("fontStyle", Font.Style.ToString());
            }
            if (BorderWidth > 0)
            {
                attributeValues.Add("borderWidth", BorderWidth.ToString(CultureInfo.InvariantCulture));
            }
            if (BorderColor != Color.Empty)
            {
                attributeValues.Add("borderColor", BorderColor.Name);
            }
            if (ForeColor != Color.Empty)
            {
                attributeValues.Add("foreColor", ForeColor.Name);
            }
            if (BackColor != Color.Empty)
            {
                attributeValues.Add("backColor", BackColor.Name);
            }
            if (BackColor2 != Color.Empty && BackColor != BackColor2)
            {
                attributeValues.Add("backColor2", BackColor2.Name);
            }
            if (GradientAngle > 0)
            {
                attributeValues.Add("gradientAngle", GradientAngle.ToString(CultureInfo.InvariantCulture));
            }
            if (Rotation != 0)
            {
                attributeValues.Add("rotation", Rotation.ToString(CultureInfo.InvariantCulture));
            }
            if (!string.IsNullOrEmpty(Image))
            {
                attributeValues.Add("image", Image);
            }
            if (ImageRepeat != ImageRepeat.None)
            {
                attributeValues.Add("imageRepeat", ImageRepeat.ToString());
            }

            if (attributeValues.Count == 0)
            {
                return;
            }

            writer.WriteStartElement("style");
            foreach (KeyValuePair <string, string> attribute in attributeValues)
            {
                writer.WriteAttributeString(attribute.Key, attribute.Value);
            }
            writer.WriteEndElement();
        }