Solved

Scaling Bitmaps

Posted on 1998-11-05
9
294 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 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…
In this Micro Tutorial viewers will learn the basic shortcuts and functions of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
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…

861 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