1. Scaling images
- Posted by Jonas Temple <jtemple at yhti.net> Nov 22, 2004
- 2364 views
- Last edited Nov 23, 2004
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 http://www.yhti.net/~jktemple
2. Re: Scaling images
- Posted by Brian Broker <bkb at cnw.com> Nov 22, 2004
- 2334 views
- Last edited Nov 23, 2004
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
3. Re: Scaling images
- Posted by Alexander Toresson <toressonodakra at swipnet.se> Nov 22, 2004
- 2320 views
- Last edited Nov 23, 2004
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? > 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. Regards, Alexander Toresson Shhh! Be vewy quiet! I'm hunting wuntime ewwows!
4. Re: Scaling images
- Posted by Jonas Temple <jtemple at yhti.net> Nov 22, 2004
- 2343 views
- Last edited Nov 23, 2004
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? :) Jonas Temple http://www.yhti.net/~jktemple
5. Re: Scaling images
- Posted by Alexander Toresson <toressonodakra at swipnet.se> Nov 22, 2004
- 2337 views
- Last edited Nov 23, 2004
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!
6. Re: Scaling images
- Posted by Jonas Temple <jtemple at yhti.net> Nov 22, 2004
- 2314 views
- Last edited Nov 23, 2004
Brian Broker wrote: > > > It's a bit more complicated than that if you want an antialiasing effect. > You can do something like this: > }}} <eucode> > -- for antialiasing effect > hdc = getDC( Win ) > w32Proc(xSetStretchBltMode,{hdc,HALFTONE}) -- HALFTONE = 4 > w32Proc(xSetBrushOrgEx,{hdc,0,0,NULL}) > releaseDC( hdc ) > </eucode> {{{ > > 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: > }}} <eucode> > constant > xSetStretchBltMode = > registerw32Procedure(gdi32,"SetStretchBltMode",{C_POINTER,C_INT}), > xSetBrushOrgEx = > registerw32Procedure(gdi32,"SetBrushOrgEx",{C_POINTER,C_INT,C_INT,C_POINTER}), > HALFTONE = 4 > </eucode> {{{ > Brian, Perfect! Exactly what I needed. Thanks a bunch! Jonas Temple http://www.yhti.net/~jktemple
7. Re: Scaling images
- Posted by Jonas Temple <jtemple at yhti.net> Nov 22, 2004
- 2322 views
- Last edited Nov 23, 2004
Alexander Toresson wrote: > 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. > Alexander, Actually, if you look at the reply from Brian Broker he provided an example that worked perfectly on WinXP! Jonas Temple http://www.yhti.net/~jktemple
8. Re: Scaling images
- Posted by fdimage Jun 18, 2013
- 2391 views
i think using rasteredgte's image programme to vb scale images, image will stay the same resolution as the original image. it is not complicated but very awesome. you can have a try.
9. Re: Scaling images
- Posted by petersalvatore Jun 27, 2013
- 2127 views
i think using rasteredgte's image programme to vb scale images, image will stay the same resolution as the original image. it is not complicated but very awesome. you can have a try.
Nice sharing. But I have never used the tools you mentioned above. ANd I also think that using CODE to scale images is a headache work.
As for myself, I used to scale images with the help of another image SDK.
It is just one of many but I do appreciate its simple way of processing.
Even though I only tried its free trial package to generate barcodes and didn′t check the cost and licensing conditions, it works great for me.
Share with you. And I will try your sharing later.
Thanks again.
Best regards, Peter