BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

JPEG Image resize with antialias?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Nicolae Fieraru
Guest





PostPosted: Tue Jul 26, 2005 10:13 pm    Post subject: JPEG Image resize with antialias? Reply with quote



Hi All,

I made a little program which resizes a JPEG image, but the thumbnails I
create have rough edges. In graphics software, there is an option to resize
the image with antialias, I wonder if there is a way to do this in my
program. Ideally I would need a free solution and easy to implement. I am
only interested in JPEG images.

Regards,
Nicolae


Back to top
Damon Chandler (TeamB)
Guest





PostPosted: Wed Jul 27, 2005 5:33 am    Post subject: Re: JPEG Image resize with antialias? Reply with quote



Hi Nicolae,
If you don't need to deploy your application on Windows 95, you could
use GDI+, which has built-in support for antialiasing. Otherwise, a
quick solution (when reducing the image's size) is to use the
StretchBlt() GDI function with the HALFTONE stretching mode. For
example, if Image1 contains the source image, and Image2 is where you
want to place the (e.g., 128x128) thumbnail, you'd do...

// make room for the thumbnail
Image2->Picture->Bitmap->PixelFormat = pf24bit;
Image2->Picture->Bitmap->Height = 0;
Image2->Picture->Bitmap->Width = 128;
Image2->Picture->Bitmap->Height = 128;

// grab a handle to the thumbnail's memory DC
// and specify the HALFTONE stretching mode
HDC const hDstDC = Image2->Picture->Bitmap->Canvas->Handle;
POINT brush_org;
GetBrushOrgEx(hDstDC, &brush_org);
SetStretchBltMode(hDstDC, HALFTONE);
SetBrushOrgEx(hDstDC, brush_org.x, brush_org.y, NULL);

// draw Image1 stretched-to-fit onto Image2
StretchBlt(
hDstDC, 0, 0, 128, 128,
Image1->Picture->Bitmap->Canvas->Handle, 0, 0,
Image1->Picture->Bitmap->Width,
Image1->Picture->Bitmap->Height,
SRCCOPY
);
// update the display
Image2->Refresh();

If you're still seeing aliasing, your best option would be to use an
antialiasing filter (say, a Gaussian filter with the proper cutoff
frequency) followed by downsampling (e.g., [url]http://tinyurl.com/2spwx)[/url].
Let me know if you need assistance designing the filter; or if you have
access to Matlab, check out the gausswin() function--the cutoff
frequency depends only on the scaling factor.

Good luck,
--
Damon (TeamB)

C++Builder Developer's Journal
http://bcbjournal.com
BCB Commonly Asked Questions
http://bcbjournal.com/bcbcaq


Nicolae Fieraru wrote:
Quote:
I made a little program which resizes a JPEG image, but the thumbnails I
create have rough edges. In graphics software, there is an option to resize
the image with antialias, I wonder if there is a way to do this in my
program. Ideally I would need a free solution and easy to implement. I am
only interested in JPEG images.

Back to top
Nicolae Fieraru
Guest





PostPosted: Wed Jul 27, 2005 7:37 am    Post subject: Re: JPEG Image resize with antialias? Reply with quote



Hi Damon,

Thank you very much for your support. My application is intended to work
only on my XP computer and I actually need to read a jpg file, resize the
image and then save it again as a jpg image file. If you have other ideas,
please share with me.
I will have a look at the GDI+ to see if I am able to use it.

Regards,
Nicolae




Back to top
Damon Chandler (TeamB)
Guest





PostPosted: Thu Jul 28, 2005 4:33 pm    Post subject: Re: JPEG Image resize with antialias? Reply with quote

Nicolae,
If you're targeting only XP, then I'd definitely suggest using GDI+.
In particular, the GDI+ Image class has a GetThumbnailImage() method,
which will do all of the work for you; see http://tinyurl.com/cf59p

Keep in mind though, that JPEG is a compressed format, which requires
decompression to get to the actual pixel data. No matter what technique
you use (GDI, GDI+, or VCL), you will have to use an intermediate array
of pixels (e.g., a bitmap) to create a thumbnail. If you want to stick
with the GDI/VCL, you can use a TJPEGImage object to load the JPG (i.e.,
decompress it into a bitmap), use the code in the previous post to
resize the bitmap, and then use the TJPEGImage class to save the
thumbnail to a JPG file.

Good luck,
Damon


Nicolae Fieraru wrote:
Quote:
Thank you very much for your support. My application is intended to work
only on my XP computer and I actually need to read a jpg file, resize the
image and then save it again as a jpg image file. If you have other ideas,
please share with me.
I will have a look at the GDI+ to see if I am able to use it.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.