function StretchBmp(SrcBmp:TBitmap;DesBmp:TBitmap;StretchRate:Integer):Boolean;
//stretch an bitmap to a smaller bmp, stretchRate is from 0 to 100.
//from tangfeng
//2003.01.19
var
P1,P2:PByteArray;
x1,y1,x2,y2,r,g,b:Integer;
begin
Result:=false;
if StretchRate>=100 then
exit;
try
DesBmp.PixelFormat:=pf24Bit;
DesBmp.Width:=SrcBmp.Width*StretchRate div 100;
DesBmp.Height:=SrcBmp.Height*StretchRate div 100;
for y1:=0 to DesBmp.Height-1 do begin
y2:=y1*100 div StretchRate; //¼ÆËã³öSourceͼÏóÖжÔÓ¦µÄÏóËصãY·½ÏòλÖõÄÖµ
P1:=DesBmp.Scanline[y1];
for x1:=0 to DesBmp.Width-1 do begin
x2:=x1*100 div StretchRate; //¼ÆËã³öSourceͼÏóÖжÔÓ¦µÄÏóËصãX·½ÏòλÖõÄÖµ
P2:=SrcBmp.ScanLine[y2];
if (x1=0) or (x1=DesBmp.Width-1) or (y1=0) or (y1=DesBmp.Height-1) then begin
P1[x1*3]:=P2[x2*3];
P1[x1*3+1]:=P2[x2*3+1];
P1[x1*3+2]:=P2[x2*3+2];
continue;
end;
r:=P2[(x2-SrcBmp.Width)*3]+P2[(x2-1)*3]+P2[(x2+SrcBmp.Width)*3]+P2[(x2+1)*3]+P2[x2*3];
g:=P2[(x2-SrcBmp.Width)*3+1]+P2[(x2-1)*3+1]+P2[(x2+SrcBmp.Width)*3+1]+P2[(x2+1)*3+1]+P2[x2*3+1];
b:=P2[(x2-SrcBmp.Width)*3+2]+P2[(x2-1)*3+2]+P2[(x2+SrcBmp.Width)*3+2]+P2[(x2+1)*3+2]+P2[x2*3+2];
P1[x1*3]:=min(P2[x2*3],r div 5);
P1[x1*3+1]:=min(P2[x2*3+1],g div 5);
P1[x1*3+2]:=min(P2[x2*3+2],b div 5);
end;
end;
Result:=true;
except
end;
end;