示例#1
0
        public Bitmap GetThumb(string path, int maxSize)
        {
            using (var original = Image.FromFile(path))
            {
                //if (original.Width <= maxSize && original.Height < maxSize)
                //    return original;

                // Figure out the ratio
                var ratioX = maxSize / (double)original.Width;
                var ratioY = maxSize / (double)original.Height;
                // use whichever multiplier is smaller
                var ratio = ratioX < ratioY ? ratioX : ratioY;

                // now we can get the new height and width
                var newHeight = Convert.ToInt32(original.Height * ratio);
                var newWidth  = Convert.ToInt32(original.Width * ratio);

                // create filter
                var filter = new ResizeBilinear(newWidth, newHeight);
                // apply the filter
                var newImage = filter.Apply(original);

                return(newImage);
            }
        }
示例#2
0
        public Bitmap GetThumb(string path, int width, int height)
        {
            using (var original = Image.FromFile(path))
            {
                // create filter
                var filter = new ResizeBilinear(width, height);
                // apply the filter
                var newImage = filter.Apply(original);

                return(newImage);
            }
        }