Re: Scaling images
- Posted by Alexander Toresson <toressonodakra at swipnet.se> Nov 22, 2004
- 2334 views
Jonas Temple wrote: > > Alexander Toresson wrote: > > > > > Since graphics in Windows is my weak spot...how does one scale an image > > > (BMP, PNG, JPEG, etc.) such that when the image is shrunk by the user > > > it doesn't look funny? What I mean by "funny" is that I have a window > > > that displays an image (using FreeImage). I want to show the image in > > > the window for a "preview" so I use the stretchBlt function in > > > Win32Lib to shrink the image. But the shrunken image does not look as > > > good as say, shrinking the image in the Windows Picture and Fax Viewer in > > > XP. > > > > > > Can this be done with stretchBlt or is more complicated than that? > > > > > > > Here's a way to do perfect scaling-down of images, using only a nearest- > > neighbour scaling routine and a mosaic (square) effect: > > > > You first have to scale the original picture up to make the width and > > height a multiple of the destination picture's size, and bigger than > > the original. Ie if the original is 1024x768, and the destination is > > 100x100, you'll have to scale it to 1100x800. For this operation, > > linear interpolation helps, but ain't necessary. > > > > Then we'll apply the mosaic effect, with a size of > > (width / dest_width)x(height / dest_height), in this example 11x8. > > > > Then we just have to scale it down to the wanted size. > > > > That all sounds good...I was hoping for a code example, though! > > Got one? :) > No, not at the moment. I'll code one. Anyway, I do not know the win32 api, and doing it in eu may be too slow. I don't know if the win32 api features a mosaic function. I'll code one 100% eu anyway. I assume it's a 24-bit bitmap kept in a sequence, that is to be processed. /Lex Shhh! Be vewy quiet! I'm hunting wuntime ewwows!