Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new <see cref="XlsxPicture"/> instance from this image.
 /// </summary>
 /// <param name="pictureName">Picture name</param>
 /// <param name="size">Picture size</param>
 /// <param name="border">Picture border</param>
 /// <param name="content">Picture content</param>
 /// <param name="shapeEffects">picture shape effects</param>
 /// <returns>
 /// A <see cref="XlsxPicture"/> reference from this image.
 /// </returns>
 public XlsxPicture AsPicture(string pictureName, XlsxBaseSize size = null, XlsxBorder border = null, XlsxPictureContent content = null, XlsxShapeEffects shapeEffects = null) =>
 new XlsxPicture
 {
     Name             = pictureName,
     UnderliyingImage = this,
     Size             = size ?? XlsxSize.Default,
     Border           = border ?? XlsxBorder.Default,
     ShapeEffects     = shapeEffects ?? XlsxShapeEffects.Default,
     Content          = content ?? XlsxPictureContent.Default,
     Path             = Path == null ? null : Path.AbsolutePath
 };
Ejemplo n.º 2
0
        /// <summary>
        /// Try to modify the picture size settings.
        /// </summary>
        /// <param name="size">Reference to picture size settings to apply</param>
        /// <returns>
        /// <para>
        /// A <see cref="BooleanResult"/> reference that contains the result of the operation, to check if the operation is correct, the <b>Success</b>
        /// property will be <b>true</b> and the <b>Value</b> property will contain the value; Otherwise, the the <b>Success</b> property
        /// will be false and the <b>Errors</b> property will contain the errors associated with the operation, if they have been filled in.
        /// </para>
        /// <para>
        /// The type of the return value is <see cref="BooleanResult"/>, which contains the operation result
        /// </para>
        /// </returns>
        public IResult SetSize(XlsxBaseSize size)
        {
            if (size == null)
            {
                return(BooleanResult.CreateErroResult("size can not be null"));
            }

            try
            {
                switch (size.Type)
                {
                case KnownSizeType.Percent:
                    Picture.SetSize((int)((XlsxPercentSize)size).Value);
                    break;

                case KnownSizeType.NullableSize:
                    var nullableSize = (XlsxNullableSize)size;
                    var hasWidth     = nullableSize.Width.HasValue;
                    var hasHeight    = nullableSize.Height.HasValue;

                    if (!hasWidth && hasHeight)
                    {
                        Picture.SetSize(Picture.Image.Width, nullableSize.Height.Value);
                    }
                    else if (hasWidth && !hasHeight)
                    {
                        Picture.SetSize(nullableSize.Width.Value, Picture.Image.Height);
                    }
                    else if (hasWidth && hasHeight)
                    {
                        Picture.SetSize(nullableSize.Width.Value, nullableSize.Height.Value);
                    }

                    break;

                default:
                case KnownSizeType.Size:
                    Picture.SetSize(((XlsxSize)size).Width, ((XlsxSize)size).Height);
                    break;
                }

                return(BooleanResult.SuccessResult);
            }
            catch (Exception e)
            {
                return(BooleanResult.FromException(e));
            }
        }