2

And hopefully with as little loss as possible, as I've heard the implementation put forward by a guy named Guido Vollbeding. Standard GDI+ doesn't seem to have this capability, and all I've found so far are either specs or fully-integrated tools. A lean, pluggable .NET component would be highly desirable. What are common pitfalls if it comes to that I have implement it myself?

Every ideas and guidances are appreciated!

EDIT: My aim is to bypass the obvious cycle of decompressing into .NET Bitmap, resizing it there then compressing it again. This article seems to point to the right way, but so far I've never seen any .NET implementation

3 Answers3

2

This is pretty easy using the .NET Bitmap class:

void ResizeImage(string inFname, string outFname, float scale)
{
    Bitmap bmpOrig = new Bitmap(inFname);
    int w = (int)(scale * bmpOrig.Width);
    int h = (int)(scale * bmpOrig.Height);
    Bitmap bmpNew = new Bitmap(bmpOrig, new Size(w, h));
    bmpNew.Save(outFname, ImageFormat.Jpeg);
}

You'll need to add a reference to System.Drawing, and use both System.Drawing and System.Drawing.Imaging in your code:

I can't say how much loss that will have.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
  • I've been using that for generic simple resize. My question is to speed it up in special cases where a better algorithm can take advantage of the 1/2, 1/4, 1/8 downscale ratios. – Heartless Angel Jan 22 '09 at 04:58
0

I don't know of any algorithms that specifically handle 1/(2^n), but if you can find one you will need to be able to lock the bits on the bitmap (if you want any reasonable form of speed). Using set/get pixel is a poor idea.

Clickety

Jonathan C Dickinson
  • 7,181
  • 4
  • 35
  • 46
0

Load it into memory as a bitmap, then get its data and use unsafe code, written like it was C++ to resize it. Here is where I learned how to resize images quickly (I don't think that link resizes them, but it shows you how to do write fast imaging code in .Net)

Setting a breakpoint and stepping through your code in the Disassembly window will tell you how you are doing. Avoid any array access, just use pointers, array access is the kiss of death to tight performance loops in .Net (because there is a check on whether the index is within the bounds and then a conditional jump to throw an exception for Every. Single. Access.)

Community
  • 1
  • 1