?
Solved

Resizing Jpeg in C++ Builder 6

Posted on 2003-03-09
10
Medium Priority
?
12,673 Views
Last Modified: 2013-12-26
I need to resize Jpeg pictures in C++ Builder, i've tried using TBitmap and scaling the picture with Canvas->StretchDraw and then assigning it back to jpeg. That works but the resized Jpeg is distorted and not as good as i want.
I've also tried using some components but not with good results.
Thanks.
0
Comment
Question by:molekul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
10 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 8108221

The VCL doesn't offer you a lot of options when dealing with jpegs.  It's a "basic" class that has few options.

You'll have to deal with a jpg as any other graphical entity.  Load it to a canvas, dink with the picture, and save it.  It sounds like you're doing that.

So now we get into picture quality -- the root of the problem.

If you select "best picture quality" you're sacrificing wall time for a better image.  If you're going to resize the picture several times I highly recommend this.

      jp = new TJPEGImage();
      jp->CompressionQuality = 50;

For most of the things that I do this is good enough.  It may not be for your purposes.

And the problem is the mathematics involved.  Every time the picture is compress or resized, part of the picture is left on the cutting room floor.  Some resizing works quite well, others causes distortion.  Cut a picture's dimensions in half.  Since the new picture contains 1/4 the pixels of the original the new pic is obviously smaller.  Now blow the picture back up to it's original size.  Depending upon the quality of the 1/2 sized picture, the new picture may look distorted or blurry.  After all the mathematics filled in the missing pixels based on the pixels around it.  It had to "make them up" by guessing.  The "guesses" are reasonably good, but not as good as an undoctored image.

For now, try the best quality compression that you can.  If this isn't good enough you'll have to invest in some 3rd party imaging software that will sharpen the image for you.

Kdo
0
 

Author Comment

by:molekul
ID: 8110595
Hi Kdo and thanks for your comment.
I think the problem is when i use the StretchDraw function.

//m_picture is a TJPEGImage

Graphics::TBitmap *bmp = new Graphics::TBitmap();

bmp->Width = newWidth;
bmp->Height = newHeight;
bmp->Canvas->StretchDraw(bmp->Canvas->ClipRect, m_picture);

m_picture->Assign(bmp);
m_picture->SaveToFile(m_pictureOutputPath);

Look at this images that i made, the former is made by this function but the latter is resized in Photoshop. Both are created from the same picture.

http://www.designplastik.com/h/bad.jpg
http://www.designplastik.com/h/good.jpg

See e.g. how his nose gets all distorted.

Thanks.

0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 500 total points
ID: 8110684

That's the loss inherent to the process.

1/3 * 3 = 1, but

.333 * 3 = .999


Every time you change the scale you lose something in the rounding.

Kent
0
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 

Author Comment

by:molekul
ID: 8111332
I think the problem is that the stretch function doesn't anti-alais the picture like when i resize in Photoshop. There must be some other way around this.
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 8111405

Sounds like you're going to have to extend the class yourself and build in this functionality.  I've got no idea where to tell you to look for this kind of software.  Perhaps another poster will know.

Kdo
0
 

Author Comment

by:molekul
ID: 8112034
I found a 3rd party component that solves my problem.
Thanks for your help though.
0
 

Author Comment

by:molekul
ID: 8112779
I found a 3rd party component that solves my problem.
Thanks for your help though.
0
 

Expert Comment

by:arunjude
ID: 8358183
Hi Guys,

I have the same problem. Can u help me out with this. I am planning to do in VC++.

Molekul have u got any solution for this reg that 3 party tool.
Replies much appreciated.

Regards
Jude
0
 

Author Comment

by:molekul
ID: 8358950
Well, i found a 3rd party component called MWA JPEG, but that's only for Borland so i'm not sure how you could do it in Visual Studio.

Hjalti
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question