public ImageProperties( float scale = 1, string semanticLabel = null, float width = 0.0f, float height = 0.0f, Color color = null, BlendMode colorBlendMode = BlendMode.srcOver, BoxFit fit = BoxFit.fill, Alignment alignment = null, ImageRepeat repeat = ImageRepeat.noRepeat, Rect centerSlice = null, bool matchTextDirection = false, FilterMode filterQuality = FilterMode.Bilinear ) { this.scale = scale; this.semanticLabel = semanticLabel; 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.matchTextDirection = matchTextDirection; this.filterQuality = filterQuality; }
public static FittedSizes applyBoxFit(BoxFit fit, Size inputSize, Size outputSize) { if (inputSize.height <= 0.0 || inputSize.width <= 0.0 || outputSize.height <= 0.0 || outputSize.width <= 0.0) { return(new FittedSizes(Size.zero, Size.zero)); } Size sourceSize = null; Size destinationSize = null; switch (fit) { case BoxFit.fill: sourceSize = inputSize; destinationSize = outputSize; break; case BoxFit.contain: sourceSize = inputSize; if (outputSize.width / outputSize.height > sourceSize.width / sourceSize.height) { destinationSize = new Size(sourceSize.width * outputSize.height / sourceSize.height, outputSize.height); } else { destinationSize = new Size(outputSize.width, sourceSize.height * outputSize.width / sourceSize.width); } break; case BoxFit.cover: if (outputSize.width / outputSize.height > inputSize.width / inputSize.height) { sourceSize = new Size(inputSize.width, inputSize.width * outputSize.height / outputSize.width); } else { sourceSize = new Size(inputSize.height * outputSize.width / outputSize.height, inputSize.height); } destinationSize = outputSize; break; case BoxFit.fitWidth: sourceSize = new Size(inputSize.width, inputSize.width * outputSize.height / outputSize.width); destinationSize = new Size(outputSize.width, sourceSize.height * outputSize.width / sourceSize.width); break; case BoxFit.fitHeight: sourceSize = new Size(inputSize.height * outputSize.width / outputSize.height, inputSize.height); destinationSize = new Size(sourceSize.width * outputSize.height / sourceSize.height, outputSize.height); break; case BoxFit.none: sourceSize = new Size(Mathf.Min(inputSize.width, outputSize.width), Mathf.Min(inputSize.height, outputSize.height)); destinationSize = sourceSize; break; case BoxFit.scaleDown: sourceSize = inputSize; destinationSize = inputSize; float aspectRatio = inputSize.width / inputSize.height; if (destinationSize.height > outputSize.height) { destinationSize = new Size(outputSize.height * aspectRatio, outputSize.height); } if (destinationSize.width > outputSize.width) { destinationSize = new Size(outputSize.width, outputSize.width / aspectRatio); } break; } return(new FittedSizes(sourceSize, destinationSize)); }