Board index » cppbuilder » How To change the image size of JPG

How To change the image size of JPG


2004-01-26 03:21:50 AM
cppbuilder78
Dear all,
I need to change the image size of JPG, eg: from width 1000 to width 100
would you tell me how to change it?
can you give me some sample code
Emmanuel
 
 

Re:How To change the image size of JPG

Emmanuel wrote:
Quote
I need to change the image size of JPG, eg: from width 1000 to width 100
would you tell me how to change it?
can you give me some sample code
Please read some threads in this newsgroup.
You will easily find an answer.
Hans.
 

Re:How To change the image size of JPG

Quote
I need to change the image size of JPG, eg: from width 1000 to width 100
would you tell me how to change it?
can you give me some sample code
#include <jpeg.hpp>
#include <memory>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
std::auto_ptr<TJPEGImage>jpeg (new TJPEGImage);
jpeg->LoadFromFile("c:\\temp\\1600x1200.jpg");
std::auto_ptr<Graphics::TBitmap>bmp(new Graphics::TBitmap);
bmp->Width = jpeg->Width/10;
bmp->Height = jpeg->Height/10;
bmp->Canvas->StretchDraw(TRect(0,0,bmp->Width, bmp->Height),
jpeg.get());
// now assign back to JPEG and save as a different file
jpeg->Assign(bmp.get());
jpeg->CompressionQuality = 92;
jpeg->SaveToFile("c:\\temp\\160x120.jpg");
}
This will use the API's StretchBlt routine to perform the downsize. If
you need anything more high-tech than that, you will have to work with
the decompressed pixel data yourself.
h^2
 

{smallsort}