views:

489

answers:

4

I need the fastest library to resize full size images (some up to 9MB in size) to multiple sizes.

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

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.

Also this will need to scale to possibly 1,000 active users.

Let me know your thoughts :)

+3  A: 

Here is winforms way

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

ArsenMkrt
The Graphics object should probably be wrapped with using instead of explicitly calling Dispose.
Turnor
you are right, I edited the post
ArsenMkrt
+2  A: 

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.

Michael McCloskey
+2  A: 

There are a lot of articles out there showing the basics of this. I've used the components from Atalasoft and found them to be of pretty good quality. There are nuances to resizing and working with JPEG images.

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.

BrianLy
A: 

I'm not sure about performance, but the open source OpenCV is an option.

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:

kenny