Solved

Scaling Bitmaps

Posted on 1998-11-05
9
293 Views
Last Modified: 2013-11-22
Hi.

How do I scale a bitmap?  I have an image of say 1024x768 and I want to display it as a thumb nail and save it at the new size (say, ~120x90)?  I can use the stretch property on a TImage, but the new size doesnt allow me to save it at the size.

Any suggestions?

Ta

Stu
0
Comment
Question by:Stuart_Johnson
  • 4
  • 4
9 Comments
 
LVL 4

Accepted Solution

by:
dwwang earned 50 total points
ID: 1345860
Try aNewImage.picture.Canvas.StretchDraw(aRect,OldImage.picture.graphic), Where aNewImage and Old Image is TImage.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1345861
Dang you got to be quick around here - already answered when I posted...

Use StrecthDraw to draw the large image onto a TBitmap which is of the required size. Then save the TBitmap.

ThumbNailBitmap.canvas.StretchDraw(rect(0, 0, ThumbNailBitmap.width,
ThumbNailBitmap.height), TheBigBitmap);

Cheers,

Raymond.
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1345862
Raymond:

Cheers *_^
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1345863
Guys this is great!  Thanks for the info.  I just gave it a go, and I'm not seeing anything :)

Heres what I want it to do.  First, I search a given directory for any JPGs and BMPs.  I create a tempory image component and load the image into it.  From here, I work out its aspect ratio and create the displayed bitmap using the new sizes x the aspect ratio.

The image is created and put into a scroll box in columns, but the image is empty.  Is there any reason why this is happening?

Stu
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1345864
I think I do not clearly understand your problem, would you give some code or more explanation?

Also, does our answer work or not?
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1345865
dwwang.  My problem is that the bitmaps are not being displayed.  They are being loaded from disk OK, but not displayed at the new size.

I want to load each JPEG and Bitmap into a scollbox so I can display them as thumb nails.  WHen Iclick on the thumb nail, another window is opened and shows the picture at its full size.

Any futher help you can offer would be appreciated.

Regards,

Stu.
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1345866
I have tried the code below and get no problem:

procedure TForm1.Button1Click(Sender: TObject);
var
   aRect:TRect;
begin
     aRect:=Rect(0,0,100,100);
     aNewImage.Canvas.StretchDraw(aRect,OldImage.picture.graphic);
end;

Where aNewImage is a TImage stays in the ScrollBox.
The idea is that A scrollBox itself has no Canvas property, you must put several TImage in it acting as thumb nails.

Actually for that purpose, I would rather suggest you use the Wang Image(TM) component coming with Win95 OSR2/Win98. It has good support for thumb nails as well as other features.

0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1345867
dwwang,

I realise that, but I am still not getting any images when creating the TImages dynamically.  I'm going to start again and see what I have mucked up.

I'll let you know.

Stu.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1345868
Wow!  Sorry its taken me so long to get back on this.  I plain forgot :)

Your solution worked very well.  Thanks you.

Stu
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Print Graphic and Text to Epson TM-T88v 12 247
oracle global variables 4 68
Tviruailstringtree sort multi columns on header click 1 61
Dynamically Created Query 3 55
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.

786 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