Solved

Scaling Bitmaps

Posted on 1998-11-05
9
295 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
Technology Partners: 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 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

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!

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…
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…
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…
In addition to being a great web-based presentation tool, Prezi also makes it easy to save your presentation as a PDF to share with others as well. Learn how in this tutorial. Select the share icon from the top menu in your Prezi editor: Select "D…

680 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