Re: Scaling images
- Posted by Brian Broker <bkb at cnw.com> Nov 22, 2004
- 2333 views
Jonas Temple 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? > > > Jonas Temple > <a href="http://www.yhti.net/~jktemple">http://www.yhti.net/~jktemple</a> > It's a bit more complicated than that if you want an antialiasing effect. You can do something like this:
-- for antialiasing effect hdc = getDC( Win ) w32Proc(xSetStretchBltMode,{hdc,HALFTONE}) -- HALFTONE = 4 w32Proc(xSetBrushOrgEx,{hdc,0,0,NULL}) releaseDC( hdc )
Now your stretchBlt should look better (with antialiasing effect). Unfortunately, the HALFTONE option is not supported on Windows 95/98/Me. Declarations for the above functions are:
constant xSetStretchBltMode = registerw32Procedure(gdi32,"SetStretchBltMode",{C_POINTER,C_INT}), xSetBrushOrgEx = registerw32Procedure(gdi32,"SetBrushOrgEx",{C_POINTER,C_INT,C_INT,C_POINTER}), HALFTONE = 4
-- Brian