um, i tryed myself but failed missrebly (scanline index out of range)


heres the code

Code:
procedure ResizeBitmapNew(imgo, imgd: TBitmap; nw, nh: Integer);
const
  MaxPixelCount = 65536;  // Change this if necessary

type
  TRGBArray = array[0..MaxPixelCount - 1] of TRGBTriple;
  pRGBArray = ^TRGBArray;

var
  Row: pRGBArray;

var
  xini, xfi, yini, yfi, saltx, salty: single;
  x, y, px, py, tpix: integer;
  PixelColor: TColor;
  r, g, b: longint;

  function MyRound(const X: Double): Integer;
  begin
    Result := Trunc(x);
    if Frac(x) >= 0.5 then
      if x >= 0 then Result := Result + 1
      else
        Result := Result - 1;
     //Result &#58;= Trunc&#40;X + &#40;-2 * Ord&#40;X < 0&#41; + 1&#41; * 0.5&#41;;
  end;

begin
  // Set target size

  imgd.Width  &#58;= nw;
  imgd.Height &#58;= nh;

  // Calcs width & height of every area of pixels of the source bitmap

  saltx &#58;= imgo.Width / nw;
  salty &#58;= imgo.Height / nh;


  yfi &#58;= 0;
  for y &#58;= 0 to nh - 1 do
  begin
    Row &#58;= imgd.ScanLine&#91;y&#93;;

    // Set the initial and final Y coordinate of a pixel area

    yini &#58;= yfi;
    yfi  &#58;= yini + salty;
    if yfi >= imgo.Height then yfi &#58;= imgo.Height - 1;

    xfi &#58;= 0;
    for x &#58;= 0 to nw - 1 do
    begin
      // Set the inital and final X coordinate of a pixel area

      xini &#58;= xfi;
      xfi  &#58;= xini + saltx;
      if xfi >= imgo.Width then xfi &#58;= imgo.Width - 1;


      // This loop calcs del average result color of a pixel area
      // of the imaginary grid

      r &#58;= 0;
      g &#58;= 0;
      b &#58;= 0;
      tpix &#58;= 0;

      for py &#58;= MyRound&#40;yini&#41; to MyRound&#40;yfi&#41; do
      begin
        for px &#58;= MyRound&#40;xini&#41; to MyRound&#40;xfi&#41; do
        begin
          Inc&#40;tpix&#41;;
          PixelColor &#58;= ColorToRGB&#40;imgo.Canvas.Pixels&#91;px, py&#93;&#41;;
          r &#58;= r + GetRValue&#40;PixelColor&#41;;
          g &#58;= g + GetGValue&#40;PixelColor&#41;;
          b &#58;= b + GetBValue&#40;PixelColor&#41;;
        end;
      end;


      // Draws the result pixel

      Row&#91;x&#93;.rgbtRed &#58;= MyRound&#40;r / tpix&#41;;
      Row&#91;x&#93;.rgbtGreen &#58;= MyRound&#40;g / tpix&#41;;
      Row&#91;x&#93;.rgbtBlue &#58;= MyRound&#40;b / tpix&#41;;

&#123;      imgd.Canvas.Pixels&#91;x, y&#93; &#58;=
        rgb&#40;MyRound&#40;r / tpix&#41;,
        MyRound&#40;g / tpix&#41;,
        MyRound&#40;b / tpix&#41;
        &#41;;   &#125;
    end;
  end;
end;

as you can see im crap at image work