Solved

Generate Thumbmails JPEG/JPEG

Posted on 1998-12-10
7
526 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

862 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now