//2010 Thomas Wassermann www.explido-software.de
interface
uses Windows, Classes, Graphics,GDIPAPI,GDIPOBJ, StdCtrls, jpeg,
ActiveX;
Procedure ScaleImage(source:TGraphic;dest:TCanvas;DestRect:Trect;Center:Boolean=true);
overload;
implementation
Procedure ScaleImage(source:TGraphic;dest:TCanvas;DestRect:Trect;Center:Boolean=true);
overload;
var
graphics : TGPGraphics;
image: TGPImage;
width, height: Integer;
faktor:Double;
STR : TMemoryStream;
X, Y:Double;
begin
STR := TMemoryStream.Create;
source.SaveToStream(STR);
STR.Position := 0;
image:= TGPImage.Create(TStreamAdapter.Create(Str));
try
width := image.GetWidth;
height := image.GetHeight;
if ((DestRect.Right - DestRect.Left) / width) < ((DestRect.Bottom -DestRect.Top)/Height)
then faktor := (DestRect.Right - DestRect.Left) / width
else faktor:= ((DestRect.Bottom -DestRect.Top)/Height);
Faktor := ABS(Faktor);
if Center
then
begin
X := ((Destrect.Right - Destrect.Left) - faktor * width ) / 2;
Y := ((Destrect.Bottom - Destrect.Top) - faktor * Height ) / 2;
end
else
begin
X := Destrect.Left;
Y := Destrect.Top;
end;
graphics := TGPGraphics.Create(dest.Handle);
try
graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);
graphics.DrawImage( image, MakeRect(X, Y , faktor * width, faktor * height), 0, 0, width, height, UnitPixel);
finally
graphics.Free;
end;
finally
STR.Free;
image.Free;
end;
end;
end;