?
Solved

Resize JPG Image

Posted on 2006-05-31
5
Medium Priority
?
8,819 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:anorganix
5 Comments
 
LVL 4

Assisted Solution

by:JeePeeTee
JeePeeTee earned 100 total points
ID: 16802368
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
 
LVL 1

Assisted Solution

by:mwbowman
mwbowman earned 100 total points
ID: 16803184

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
 
LVL 3

Assisted Solution

by:EtherZa
EtherZa earned 400 total points
ID: 16806257
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
 
LVL 4

Author Comment

by:anorganix
ID: 16850987
Graphics32 is preety good at rotating images... but it's too complicated for my purpose...
Any other concise examples?

Thanks,
  Cosmin.
0
 
LVL 4

Accepted Solution

by:
4Rabbits earned 400 total points
ID: 16929740
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
In this Micro Tutorial viewers will learn the basic shortcuts and functions of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.
Suggested Courses
Course of the Month16 days, 2 hours left to enroll

850 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