Exemplo n.º 1
0
        /// <summary>
        /// Sets the new size of the image (not including the border)
        /// </summary>
        /// <param name="size"></param>
        /// <param name="sizeName"></param>
        public void SetImageSize(Size size, ImageSizeName?sizeName)
        {
            IHTMLImgElement imgElement = (IHTMLImgElement)ImgElement;

            ImageBorderMargin borderMargin = BorderMargin;
            // The next line is a little bit tortured, but
            // I'm trying to introduce the concept of "calculated image size"
            // for more complex border calculations without breaking any
            // existing logic.
            Size sizeWithBorder = ImageSize.Equals(size)
                ? ImageSizeWithBorder : borderMargin.CalculateImageSize(size);

            if (imgElement.width != sizeWithBorder.Width || imgElement.height != sizeWithBorder.Height)
            {
                imgElement.width  = sizeWithBorder.Width;
                imgElement.height = sizeWithBorder.Height;
            }

            //remember the size offsets which are added by CSS margins/padding
            Settings.SetInt(IMAGE_WIDTH_OFFSET, imgElement.width - sizeWithBorder.Width);
            Settings.SetInt(IMAGE_HEIGHT_OFFSET, imgElement.height - sizeWithBorder.Height);

            if (sizeName != null)
            {
                ImageSizeName = sizeName.Value;
            }

            //Initialize the saved aspect ratio if it has no value
            //OR update it if the ratio has been changed
            Size targetSize = TargetAspectRatioSize;

            if (targetSize.Width == -1 ||
                (size.Width != Math.Round((targetSize.Width * (float)size.Height) / targetSize.Height) &&
                 size.Height != Math.Round((targetSize.Height * (float)size.Width) / targetSize.Width)))
            {
                TargetAspectRatioSize = size;
            }
        }
Exemplo n.º 2
0
        public Bitmap ApplyImageDecorators(Bitmap bitmap)
        {
            _currImage     = bitmap;
            _originalImage = bitmap;

            bool borderNeedsReset = true;

            foreach (ImageDecorator decorator in _decoratorsList)
            {
                ApplyImageDecorator(decorator, _currImage, ref borderNeedsReset);
            }

            //update the rotation and size info in the image properties
            if (_embedType == ImageEmbedType.Embedded)
            {
//                if (borderNeedsReset)
//                    BorderMargin = ImageBorderMargin.Empty;

                if (!ImageHelper2.IsAnimated(_currImage))
                {
                    Size currImageSize = _currImage.Size;

                    //update the inline image size (don't forget to remove size added by borders)
                    ImageBorderMargin borderMargin = BorderMargin;
                    Size borderlessImageSize       = new Size(
                        currImageSize.Width - borderMargin.Width,
                        currImageSize.Height - borderMargin.Height);
                    _imageInfo.InlineImageSize = borderlessImageSize;
                }
            }
            else
            {
                _imageInfo.LinkTargetImageSize = _currImage.Size;
            }

            _originalImage = null;
            return(_currImage);
        }