Board index » delphi » Downsizing/Stretching a Bitmap

Downsizing/Stretching a Bitmap


2003-11-29 10:29:37 PM
delphi78
I Have a TBitmap that is of a variable size but want to shrink it or expand
it to a fixed size but keep the same proportion of length to width .... how
can I do this? thanks, LL
 
 

Re:Downsizing/Stretching a Bitmap

Lon Layton writes:
Quote
I Have a TBitmap that is of a variable size but want to shrink it or expand
it to a fixed size but keep the same proportion of length to width .... how
can I do this?
This is a *very* simple mathematical problem. I believe you should think a moment yourself and you should find a good solution. If you want to become a programmer then you should indeed know a view basic algorithms ;-)
Mike
--
www.delphi-gems.com
www.delphi-unicode.net
www.lischke-online.de
 

Re:Downsizing/Stretching a Bitmap

Mike Lischke writes:
Quote
a view basic
OMG, ... a few basic ...
Mike
--
www.delphi-gems.com
www.delphi-unicode.net
www.lischke-online.de
 

Re:Downsizing/Stretching a Bitmap

Try this function - just change the commented out line depending on
whether you want to reset the width or height - dont forget to set the
base wifht ot height to what you want.
function resizePImage(sInImage, sOutImage: string; iheight, iwidth:
integer): boolean;
var
JpgImg: TJpegImage;
BmpImg: TBitmap;
Rectangle: TRect;
begin
try
JpgImg := TJpegImage.Create;
BmpImg := TBitmap.Create;
JpgImg.LoadFromFile(sInImage);
Iheight:=600;
//Iwidth:=800;
//Iheight:=round(JpgImg.height / (jpgImg.width /
strtofloat(inttostr(Iwidth))));
Iwidth := round(JpgImg.Width / (jpgImg.Height /
strtofloat(IntToStr(Iheight))));
with BmpImg do
begin
Width := iWidth;
Height := iHeight;
Rectangle := Rect(0, 0, Width, Height);
Canvas.StretchDraw(Rectangle, JpgImg);
end;
finally
if jpgimg.Width < jpgimg.Height then
begin
JpgImg.Assign(BmpImg);
JpgImg.SaveToFile(sOutImage);
end;
JpgImg.Free;
BmpImg.Free;
end;
Result := True;
end;
On Sat, 29 Nov 2003 09:29:37 -0500, "Lon Layton" <XXXX@XXXXX.COM>
writes:
Quote
I Have a TBitmap that is of a variable size but want to shrink it or expand
it to a fixed size but keep the same proportion of length to width .... how
can I do this? thanks, LL

 

Re:Downsizing/Stretching a Bitmap

Having a good view on basic algorithms is also important.. :)
Nils
"Mike Lischke" <XXXX@XXXXX.COM>writes
Mike Lischke writes:
Quote
a view basic
OMG, ... a few basic ...
Mike
--
www.delphi-gems.com
www.delphi-unicode.net
www.lischke-online.de