Resize JPG Image

Hi all!
I need to resize a serie of large JPG images (4000x2000) and I need a *fast* algo that will do the job...

Currently I am using a procedure based on "StrechDraw", but it's not fast enough:

//////////////////////// code /////////////////////////

procedure ResizeJPG(InFile, OutFile: string; Percent, Quality: integer);
var
  oJPG: TJPEGImage;
  oBmp: TBitmap;
begin
  try
    oJPG:=TJPEGImage.Create;
    oJPG.LoadFromFile(InFile);
  except
    MessageBox(0,PChar('Cannot open '+ExtractFileName(InFile)+'!'),
               'Error',MB_OK+MB_ICONERROR);
    Exit;
  end;

  oBmp:=TBitmap.Create;
  oBmp.Width:=Round(oJPG.Width*Percent/100);
  oBmp.Height:=Round(oJPG.Height*Percent/100);
  oBmp.Canvas.StretchDraw(Rect(0,0,oBmp.Width-1,oBmp.Height-1),oJPG);

  oJPG.Assign(oBmp);
  oJPG.CompressionQuality:=Quality;
  oJPG.Compress;
  oJPG.SaveToFile(OutFile);

  oBmp.Free;
  oJPG.Free;
end;

///////////////////////// end code /////////////////////////

I will raise the points if I get a good solution!
Thanks in advance!

  :: Cosmin
LVL 4
anorganixAsked:
Who is Participating?
 
4RabbitsConnect With a Mentor Commented:
uses ...Jpeg, Graphics;

function resizeImage(sInImage, sOutImage: string; iHeight, iWidth: integer): boolean;
var JpgImg : TJpegImage;
   BmpImg : TBitmap;
   Rectangle: TRect;
begin
   try
    JpgImg := TJpegImage.Create;
    BmpImg := TBitmap.Create;
   
    JpgImg.LoadFromFile(sInImage);
    Rectangle := Rect(0, 0, iWidth, iHeight);
    with BmpImg do
    begin
    Width := iWidth;
    Height := iHeight;
    Canvas.StretchDraw(Rectangle, JpgImg);
    end;
    finally
    JpgImg.Assign(BmpImg);
    JpgImg.SaveToFile(sOutImage);
    JpgImg.Free;
    BmpImg.Free;
    end;
   Result := True;
   end;
0
 
JeePeeTeeConnect With a Mentor Commented:
Hi Anorganix,

I use this lib found on: http://www.delphi32.com/vcl/657/

It works great for me when I use it like.... Strecth(MasterBMP,MasterResized,ResampleFilters[5].Filter,ResampleFilters[5].Width);

0
 
mwbowmanConnect With a Mentor Commented:

You can also try TPicShow available here:

  http://www.torry.net/quicksearchd.php?String=picshow&Title=Yes

Along with providing "stretch" capabilities, it also allows you to include various transitions between pictures they're viewed and other options...
0
 
EtherZaConnect With a Mentor Commented:
Have a look at Graphics32 - its open source, quick and will be able to do what you are looking for. It also allows for resampling/image manipulation.

http://www.graphics32.org/wiki/
0
 
anorganixAuthor Commented:
Graphics32 is preety good at rotating images... but it's too complicated for my purpose...
Any other concise examples?

Thanks,
  Cosmin.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.