关于c#:我可以使用哪个免费的图像大小调整库来调整大小并提供图像?

Which free image resizing library can I use for resizing and probably serving images?

我用过Umbraco,那里有一个非常不错的ImageGen库,它可以即时调整图像大小并兑现处理过的图像。

在Umbraco之外是否可以使用类似的东西?

(我以为我可以在没有Umbraco的情况下使用ImageGen,但看起来它不是免费的)

谢谢


我知道这个问题已经很老了,但是由于我仍然偶然发现了这个问题,所以我认为应该发表我的发现。

http://imageprocessor.org/似乎是一个相对较新的库,它是免费的开放源代码,并且也具有许多功能!


我写了ImageResizer HttpModule,它是免费的,开源的,并通过StackOverflow imageresizer标记免费提供支持。

它有39个插件,其中一些需要许可证,但是所有内容的所有源代码都可以从http://imageresizing.net/download获得。

它适用于所有.NET CMS,包括Umbraco。

与ImageGen不同,它旨在扩展到数百万张图像。


.NET Framework包括对图像大小调整的支持。

下面是我的书《 Ultra-Fast ASP.NET》中的一些示例代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.IO;

namespace Samples
{
    public class ImageResizer
    {
        private static ImageCodecInfo jpgEncoder;

        public static void ResizeImage(string inFile, string outFile, double maxDimension, long level)
        {
            //
            // Load via stream rather than Image.FromFile to release the file
            // handle immediately
            //
            using (Stream stream = new FileStream(inFile, FileMode.Open))
            {
                using (Image inImage = Image.FromStream(stream))
                {
                    double width;
                    double height;

                    if (inImage.Height < inImage.Width)
                    {
                        width = maxDimension;
                        height = (maxDimension / (double)inImage.Width) * inImage.Height;
                    }
                    else
                    {
                        height = maxDimension;
                        width = (maxDimension / (double)inImage.Height) * inImage.Width;
                    }
                    using (Bitmap bitmap = new Bitmap((int)width, (int)height))
                    {
                        using (Graphics graphics = Graphics.FromImage(bitmap))
                        {
                            graphics.SmoothingMode = SmoothingMode.HighQuality;
                            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                            graphics.DrawImage(inImage, 0, 0, bitmap.Width, bitmap.Height);
                            if (inImage.RawFormat.Guid == ImageFormat.Jpeg.Guid)
                            {
                                if (jpgEncoder == null)
                                {
                                    ImageCodecInfo[] ici = ImageCodecInfo.GetImageDecoders();
                                    foreach (ImageCodecInfo info in ici)
                                    {
                                        if (info.FormatID == ImageFormat.Jpeg.Guid)
                                        {
                                            jpgEncoder = info;
                                            break;
                                        }
                                    }
                                }
                                if (jpgEncoder != null)
                                {
                                    EncoderParameters ep = new EncoderParameters(1);
                                    ep.Param[0] = new EncoderParameter(Encoder.Quality, level);
                                    bitmap.Save(outFile, jpgEncoder, ep);
                                }
                                else
                                    bitmap.Save(outFile, inImage.RawFormat);
                            }
                            else
                            {
                                //
                                // Fill with white for transparent GIFs
                                //
                                graphics.FillRectangle(Brushes.White, 0, 0, bitmap.Width, bitmap.Height);
                                bitmap.Save(outFile, inImage.RawFormat);
                            }
                        }
                    }
                }
            }
        }

        public static void GetImageSize(string inFile, out int width, out int height)
        {
            using (Stream stream = new FileStream(inFile, FileMode.Open))
            {
                using (Image src_image = Image.FromStream(stream))
                {
                    width = src_image.Width;
                    height = src_image.Height;
                }
            }
        }
    }
}