Solved

Generate Thumbmails JPEG/JPEG

Posted on 1998-12-10
7
543 Views
Last Modified: 2010-04-04
I need a few simple rutines to do following:
like Procedure big2small( Infile,outfile : string; MaxH, MaxW : integer);

Infile = Jpeg
Outfile = jpeg
MaxH = Max height of output pic, keep aspect ratio,
MaxW = max width -"-

More options allowed if any good ideas..

PS: In delphi 3.x  NOT delphi 4 and nOT OCX

Not interested in Buyware components Thanks.
0
Comment
Question by:brainware
7 Comments
 
LVL 2

Author Comment

by:brainware
ID: 1350482
Edited text of question
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1350483
Why not use the thumbnails function provided by WangImage(TM),
it's an OCX included in Win95. It's now the world leading Image process software and totally free!
0
 
LVL 2

Author Comment

by:brainware
ID: 1350484
I will look into that, i tryed it long time ago, forgot that one :)
well.. hope its in NT too else ill just have to use win9x to do the job.
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!

 
LVL 2

Author Comment

by:brainware
ID: 1350485
Edited text of question
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 150 total points
ID: 1350486
Hi

(I assume you already know about the JPeg folder on the Delphi 3 CDROM.  You will need the JPeg unit from the CDROM to do what I explain below.  Delphi 4 includes the JPeg unit when you install Delphi.)

The StretchBlt API allows you to resize an image (e.g. bitmap).  Unfortunately you need a canvas to work with, and Delphi's TJPegImage doesn't have a canvas.  I have overcome this problem before by using "dummy" bitmaps as follows:

procedure CreateThumbnail(jpBig, jpSmall: TJpegImage; NewWidth, NewHeight: Integer);
var
  BmpBig, BmpSmall: TBitmap;
begin
  // Create the temp bitmaps.
  BmpBig := TBitmap.Create;
  BmpSmall := TBitmap.Create;

  // Assign the "big" bitmap to the "big" JPEG.
  BmpBig.Assign(jpBig);

  // Create the "small" bitmap.
  BmpSmall.Width := NewWidth;
  BmpSmall.Height := NewHeight;
  StretchBlt(BmpSmall.Canvas.Handle, 0, 0, NewWidth, NewHeight, BmpBig.Canvas.Handle, 0, 0, jpBig.Width, jpBig.Height, SRCCOPY);

  // Assign the "small" JPEG to the "small" bitmap.
  jpSmall.Assign(BmpSmall);

  // Free the temp bitmaps.
  BmpBig.Free;
  BmpSmall.Free;
end;


This would then be called as follows:

var
  jpBig, jpSmall: TJPegImage;
begin
  jpBig := TJPegImage.Create;
  jpSmall := TJPegImage.Create;

  jpBig.LoadFromFile('Test.jpg');

  CreateThumbnail(jpBig, jpSmall, 120, Round((120 / jpBig.Width) * jpBig.Height));

  jpSmall.SaveToFile('Test2.jpg');

  jpSmall.Free;
  jpBig.Free;
end;

(NOTE: You will need to add "JPeg" to your uses clause.)

Cheers,
JB

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1350487
JimBob's solution is perfect... If you use the OCX you have to supply the OCX if you try to run the software on another computer that doesn't have that OCX...so better use simple solution... No need to get your hands dirty with the OCXes....

Cheers,
Viktor
0
 
LVL 2

Author Comment

by:brainware
ID: 1350488
I Tryed your code with StretchBlt, Its almost worth using :)
Well it (Edited by Computer101) Colors and (Edited by Computer101) up...
I think i know how to fix, But you are welcome to Add as Comment..
Mvh
Michael
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

685 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