Solved

Scaling Bitmaps

Posted on 1998-11-05
9
292 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
 
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
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 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

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

Suggested Solutions

Title # Comments Views Activity
Need icon art 9 96
Delphi XE10 Round Image 2 76
Strange behavior when a form is closed 6 51
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 27
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…
Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
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.
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…

919 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

13 Experts available now in Live!

Get 1:1 Help Now