Hi, in my latest experiment, I came up with a really simple way of modifying nearestneighbour into copy_from_left/top; it suffices to indicate half a pixel translation, as in this C# code. The source image has size (w,h) and is translated to (x,y) and scaled up by the fraction zoomT/zoomN:
Rectangle r=new Rectangle(x, y, w\*zoomT/zoomN, h\*zoomT/zoomN);
g.InterpolationMode=InterpolationMode.NearestNeighbor;
g.DrawImage(image, r, -0.5f, -0.5f, w, h, GraphicsUnit.Pixel);
So instead of using the pixels 0, 1, 2, ... w-1 of the source image, I am actually using the pixels -0.5, 0.5, 1.5, ... w-1.5 which means whenever I need something in some interval (say the first -0.5 to 0.5) it will take the nearest integer, which is the middle of the translated interval, i.e. the left/top of the original interval! Can't get more simple than that. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|