Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12725
  • Last Modified:

Resizing Jpeg in C++ Builder 6

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
molekul
Asked:
molekul
  • 5
  • 3
1 Solution
 
Kent OlsenData Warehouse Architect / DBACommented:

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
 
molekulAuthor Commented:
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
 
Kent OlsenData Warehouse Architect / DBACommented:

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
molekulAuthor Commented:
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
 
Kent OlsenData Warehouse Architect / DBACommented:

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
 
molekulAuthor Commented:
I found a 3rd party component that solves my problem.
Thanks for your help though.
0
 
molekulAuthor Commented:
I found a 3rd party component that solves my problem.
Thanks for your help though.
0
 
arunjudeCommented:
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
 
molekulAuthor Commented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now