Solved

Scaling Bitmaps

Posted on 1998-11-05
9
291 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
Comment Utility
Try aNewImage.picture.Canvas.StretchDraw(aRect,OldImage.picture.graphic), Where aNewImage and Old Image is TImage.
0
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
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
Comment Utility
Raymond:

Cheers *_^
0
 
LVL 6

Author Comment

by:Stuart_Johnson
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 4

Expert Comment

by:dwwang
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
I've been using this technique since Adobe CS2, and it should work with any version of Illustrator that includes the appearance panel. In this tutorial we'll create a button using the appearance panel in Adobe Illustrator, and then save it as a r…
In this Micro Tutorial viewers will learn how to remove an unwanted object using Photoshop’s feature known as content-aware fill.
Not only does Prezi allow you to create non-linear presentations, it also makes it easy to apply transition animations between your frames. Learn how to apply a fade-in transition to select items and entire frames in this tutorial Select "Edit Path"…

771 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

15 Experts available now in Live!

Get 1:1 Help Now