Ejemplo n.º 1
0
        public breinImage GetThumbnailImage(int width, int height, ThumbnailMethod method)
        {
            breinImage image;
            double     imageRatio = (double)_image.Width / _image.Height;
            double     thumbRatio = (double)width / height;

            if (method == ThumbnailMethod.Crop)
            {
                int imgWidth  = width;
                int imgHeight = height;

                if (imageRatio < thumbRatio)
                {
                    imgHeight = (_image.Height * width) / _image.Width;
                }
                else
                {
                    imgWidth = (_image.Width * height) / _image.Height;
                }

                image = new breinImage(width, height);
                DrawScaledImage(image._image, _image, (width - imgWidth) / 2, (height - imgHeight) / 2, imgWidth, imgHeight);
            }
            else if (method == ThumbnailMethod.Pad)
            {
                // Rewritten to fix issue #1. Thanks to Cosmin!
                float hRatio    = _image.Height / (float)height;
                float wRatio    = _image.Width / (float)width;
                float newRatio  = hRatio > wRatio ? hRatio : wRatio;
                int   imgHeight = (int)(_image.Height / newRatio);
                int   imgWidth  = (int)(_image.Width / newRatio);

                image = new breinImage(width, height, _backgroundColor);
                DrawScaledImage(image._image, _image, (width - imgWidth) / 2, (height - imgHeight) / 2, imgWidth, imgHeight);
            }
            else   // ThumbnailMethod.Fit
            {
                if (imageRatio < thumbRatio)
                {
                    width = (_image.Width * height) / _image.Height;
                }
                else
                {
                    height = (_image.Height * width) / _image.Width;
                }

                image = new breinImage(width, height);
                DrawScaledImage(image._image, _image, 0, 0, width, height);
            }

            return(image);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create an exact copy of this breinstormin.tools.image.breinImage
        /// </summary>
        /// <returns></returns>
        public breinImage Clone()
        {
            // Create new image from the old one
            breinImage newImage = new breinImage(_image);

            // Set all private variables to same as the current instance
            newImage._color             = _color;
            newImage._font              = _font;
            newImage._backgroundColor   = _backgroundColor;
            newImage._textrenderinghint = _textrenderinghint;

            return(newImage);
        }
Ejemplo n.º 3
0
 public void BlitFill(breinImage image)
 {
     BlitFill(image._image);
 }
Ejemplo n.º 4
0
 public void BlitImage(breinImage image, int x, int y)
 {
     BlitImage(image._image, x, y);
 }
Ejemplo n.º 5
0
 public void BlitImage(breinImage image)
 {
     BlitImage(image._image, 0, 0);
 }
Ejemplo n.º 6
0
        public breinImage GetThumbnailImage(int width, int height, ThumbnailMethod method)
        {
            breinImage image;
            double imageRatio = (double)_image.Width / _image.Height;
            double thumbRatio = (double)width / height;

            if(method == ThumbnailMethod.Crop ) {
                int imgWidth = width;
                int imgHeight = height;

                if(imageRatio < thumbRatio) {
                    imgHeight = (_image.Height * width) / _image.Width;
                }
                else {
                    imgWidth = (_image.Width * height) / _image.Height;
                }

                image = new breinImage(width, height);
                DrawScaledImage(image._image, _image, (width - imgWidth) / 2, (height - imgHeight) / 2, imgWidth, imgHeight);
            }
            else if(method == ThumbnailMethod.Pad) {
                // Rewritten to fix issue #1. Thanks to Cosmin!
                float hRatio = _image.Height / (float)height;
                float wRatio = _image.Width / (float)width;
                float newRatio = hRatio > wRatio ? hRatio : wRatio;
                int imgHeight = (int)(_image.Height / newRatio);
                int imgWidth = (int)(_image.Width / newRatio);

                image = new breinImage(width, height, _backgroundColor);
                DrawScaledImage(image._image, _image, (width - imgWidth) / 2, (height - imgHeight) / 2, imgWidth, imgHeight);
            }
            else { // ThumbnailMethod.Fit
                if(imageRatio < thumbRatio) {
                    width = (_image.Width * height) / _image.Height;
                }
                else {
                    height = (_image.Height * width) / _image.Width;
                }

                image = new breinImage(width, height);
                DrawScaledImage(image._image, _image, 0, 0, width, height);
            }

            return image;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create an exact copy of this breinstormin.tools.image.breinImage
        /// </summary>
        /// <returns></returns>
        public breinImage Clone()
        {
            // Create new image from the old one
            breinImage newImage = new breinImage(_image);

            // Set all private variables to same as the current instance
            newImage._color = _color;
            newImage._font = _font;
            newImage._backgroundColor = _backgroundColor;
            newImage._textrenderinghint = _textrenderinghint;

            return newImage;
        }
Ejemplo n.º 8
0
 public void BlitImage(breinImage image, int x, int y)
 {
     BlitImage(image._image, x, y);
 }
Ejemplo n.º 9
0
 public void BlitImage(breinImage image)
 {
     BlitImage(image._image, 0, 0);
 }
Ejemplo n.º 10
0
 public void BlitFill(breinImage image)
 {
     BlitFill(image._image);
 }