C# .NET 中最快的图像大小调整
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1195064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fastest Image Resizing in .NET
提问by Ash
I need the fastest library to resize full size images (some up to 9MB in size) to multiple sizes.
我需要最快的库来将全尺寸图像(一些尺寸高达 9MB)调整为多种尺寸。
Here's the scenerio:
这是场景:
- User uploads a photo
- a FileSystemWatcher is running in a service watching the drop location (on a SAN)
- When a new photo appears, the service will create 4 versions of the image at full JPEG quality:
- 100px wide
- 320px wide
- 640px wide
- 1280 wide
- 用户上传照片
- FileSystemWatcher 正在监视放置位置的服务中运行(在 SAN 上)
- 当出现一张新照片时,该服务将以全 JPEG 质量创建 4 个版本的图像:
- 100 像素宽
- 320px 宽
- 640px 宽
- 1280宽
I'm not fussed if the library is C/C++ or anything else for that matter, as long as I can tap into it via .NET it's cool.
如果库是 C/C++ 或其他任何东西,我不会大惊小怪,只要我可以通过 .NET 使用它就很酷。
Also this will need to scale to possibly 1,000 activeusers.
此外,这将需要扩展到可能有 1,000 个活跃用户。
Let me know your thoughts :)
让我知道你的想法 :)
采纳答案by Brian Lyttle
There are a lot of articles out there showing the basics of this. I've used the components from Atalasoftand found them to be of pretty good quality. There are nuances to resizing and working with JPEG images.
有很多文章展示了这方面的基础知识。我使用了Atalasoft的组件,发现它们的质量非常好。调整大小和处理 JPEG 图像存在细微差别。
You seem to be really concerned with performance but you don't really give enough information to help us suggest good optimizations for you. Whatever you are doing, you need to do a full performance analysis and understand what is running slow. In some cases slowish, but maintainable image processing code may be OK if other things are optimized.
您似乎真的很关心性能,但您并没有真正提供足够的信息来帮助我们为您提出好的优化建议。无论您在做什么,您都需要进行全面的性能分析并了解运行缓慢的原因。在某些情况下速度较慢,但如果优化了其他内容,则可维护的图像处理代码可能没问题。
One solution for good performance is to queue incoming files that need to be converted. Add more machines to handle more messages in the queue, or optimize the service code to get better throughput. It's really not that difficult to handle a large number of users if you get the design right.
获得良好性能的一种解决方案是将需要转换的传入文件排队。添加更多机器以处理队列中的更多消息,或优化服务代码以获得更好的吞吐量。如果设计得当,处理大量用户其实并不难。
回答by Arsen Mkrtchyan
Here is winforms way
这是winforms方式
public Image ResizeImage( Image img, int width, int height )
{
Bitmap b = new Bitmap( width, height ) ;
using(Graphics g = Graphics.FromImage( (Image ) b ))
{
g.DrawImage( img, 0, 0, width, height ) ;
}
return (Image ) b ;
}
and here is WPF way TransformedBitmap Class
这是 WPF 方式TransformedBitmap 类
回答by Michael A. McCloskey
If money is no object, LeadTools is the traditional "go to" library for image processing. That being said, my first inclination would be to code it up using stock .NET GDI+ calls and then do some testing. It is likely this solution would be performant enough, but if not, you'll have a baseline from which you can compare other libraries and solutions. Anything involving spawning a command line tool will entail creating a separate process for each image, which could negate the benefit of going to unmanaged code.
如果钱不是问题,LeadTools 就是传统的图像处理“首选”库。话虽如此,我的第一个倾向是使用股票 .NET GDI+ 调用对其进行编码,然后进行一些测试。此解决方案可能足够高效,但如果不是,您将拥有一个基准,您可以从中比较其他库和解决方案。任何涉及生成命令行工具的事情都需要为每个图像创建一个单独的进程,这可能会抵消使用非托管代码的好处。
回答by kenny
I'm not sure about performance, but the open source OpenCVis an option.
我不确定性能,但开源 OpenCV是一种选择。
void cvResize( const CvArr* I, CvArr* J, int interpolation=CV_INTER_LINEAR );
void cvResize(const CvArr* I, CvArr* J, int interpolation=CV_INTER_LINEAR );
The function cvResize resizes image I so that it fits exactly to J. If ROI is set, the function consideres the ROI as supported as usual. the source image using the specified structuring element B that determines the shape of a pixel neighborhood over which the minimum is taken:
函数 cvResize 调整图像 I 的大小,使其完全适合 J。如果设置了 ROI,该函数会像往常一样认为 ROI 受支持。源图像使用指定的结构元素 B 确定像素邻域的形状,在该元素上取最小值:
回答by pixparker
I recommend ImageResizer:
我推荐ImageResizer:
Key features are:
主要特点是:
- RESTful url-based image API (example: src="img.jpg?w=170")
- Intuitively crop, resize, rotate, flip, constrain, and encode
- Render PDFs into images
- 19 free plugins cover most common tasks
- Disk + Memory input/output caching
- 8-bit PNG/GIF & animated GIF processing
- Flexible text & image overlay support
- Image filtering suite (needs licence)
- High performance
- and more ....
- 基于 RESTful url 的图像 API(示例:src="img.jpg?w=170")
- 直观地裁剪、调整大小、旋转、翻转、约束和编码
- 将 PDF 渲染为图像
- 19 个免费插件涵盖了最常见的任务
- 磁盘 + 内存输入/输出缓存
- 8 位 PNG/GIF 和动画 GIF 处理
- 灵活的文本和图像叠加支持
- 图像过滤套件(需要许可证)
- 高性能
- 和更多 ....
For installing with Nuget:
使用 Nuget 安装:
PM> Install-Package ImageResizer.MvcWebConfig
PM> Install-Package ImageResizer.Plugins.DiskCache
PM> Install-Package ImageResizer.Plugins.PrettyGifs
For more information please check: http://imageresizing.net/docs/install/nuget
有关更多信息,请查看:http: //imageresizing.net/docs/install/nuget